我正在xamp上工作,使用laravel 5.2并试图连接oracle数据库这里我想在tinker中获取值:
DB::table('dept')->get();
出现错误:
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
我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' => '',
],
安装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
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
],
],
在你的.env
:
DB_CONNECTION=my_connection
DB_HOST=111.111.111.111
DB_SERVICE_NAME=service
DB_DATABASE=db
DB_USERNAME=user
DB_PASSWORD=pass