0

I am working on xamp, using laravel 5.2 and trying to connect oracle database here I want to get values in tinker:

DB::table('dept')->get();

with this error:

PDOException with message 'could not find driver'

my .env file

DB_CONNECTION=sqlsrv
DB_HOST=localhost
DB_PORT=1521
DB_DATABASE=Mydb
DB_USERNAME=db_username
DB_PASSWORD=password

my database.php

'default' => env('DB_CONNECTION', 'sqlsrv'),

...

    'sqlsrv' => [
        'driver' => 'sqlsrv',
        'host' => env('DB_HOST', 'localhost'),
        'database' => env('DB_DATABASE', 'Mydb'),
        'username' => env('DB_USERNAME', 'db_username'),
        'password' => env('DB_PASSWORD', 'password'),
        'charset' => 'utf8',
        'prefix' => '',
    ],
9
  • You need to install the driver: php.net/manual/en/… Commented Nov 7, 2016 at 17:52
  • will this driver work for oracle as well? Commented Nov 7, 2016 at 17:55
  • Wait, why are you using sqlsrv to connect to an Oracle DB? That driver is for MS SQL Server. Commented Nov 7, 2016 at 17:56
  • ok i see. laravel.com/docs/5.2/database i thought laravel will make this work for oracle as well. Commented Nov 7, 2016 at 17:59
  • i there in laravel a connection to oracle similar to sql server? Commented Nov 7, 2016 at 18:01

1 Answer 1

1

Install Oracle client in your machine: http://www.oracle.com/technetwork/database/features/instant-client/index-097480.html

Install/enable Oracle for PHP. That will depend on your operation system. In windows, I believe you only need to enable on your php.ini, extension=pdo_oci.dll. In linux, you need to install, with apt get or similar in your distro, or recompile PHP with instructions on this page: http://php.net/manual/en/ref.pdo-oci.php

Use this library in your Laravel project: https://github.com/yajra/laravel-oci8

In config/database.php:

'default' => env('DB_CONNECTION', 'my_connection'),

'connections' => [
    'my_connection' => [
        'driver'   => 'oracle',
        'host'     => env('DB_HOST', 'localhost'),
        'port'     => env('DB_PORT', '1521'),
        'service_name' => env('DB_SERVICE_NAME', ''),
        'database' => env('DB_DATABASE', ''),
        'username' => env('DB_USERNAME', ''),
        'password' => env('DB_PASSWORD', ''),
        'charset'  => 'utf8',
        'prefix'   => '',
        'options' => [
            PDO::ATTR_PERSISTENT => true
        ],
    ],

In your .env:

DB_CONNECTION=my_connection
DB_HOST=111.111.111.111
DB_SERVICE_NAME=service
DB_DATABASE=db
DB_USERNAME=user
DB_PASSWORD=pass
Sign up to request clarification or add additional context in comments.

1 Comment

thanks, my problem was with oracle oci driver, i have it installed succesfully

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.