Laravel 5.2 oracle数据库PDOException

时间:2016-11-07 17:49:02

标签: php oracle laravel

我正在使用laravel 5.2并尝试连接oracle数据库 在这里,我想要修补价值:

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

出现此错误:

PDOException with message 'could not find driver'

我的.env文件

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

我的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' => '',
    ],

1 个答案:

答案 0 :(得分:0)

在您的计算机上安装Oracle客户端:http://www.oracle.com/technetwork/database/features/instant-client/index-097480.html

安装/启用Oracle for PHP。这取决于您的操作系统。在Windows中,我相信你只需要在php.ini上启用extension=pdo_oci.dll。在linux中,您需要在发行版中使用apt get或类似版本进行安装,或者使用此页面上的说明重新编译PHP:http://php.net/manual/en/ref.pdo-oci.php

在Laravel项目中使用此库:https://github.com/yajra/laravel-oci8

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
        ],
    ],

.env

DB_CONNECTION=my_connection
DB_HOST=111.111.111.111
DB_SERVICE_NAME=service
DB_DATABASE=db
DB_USERNAME=user
DB_PASSWORD=pass