windows 系統
一、PHP开启oci8
1.下载 Oracle Instant Client
下载后解压到系统盘(本人解压到D盘)
设置系统环境变量并重启电脑
2.下载VC_redist.x64,安装
3.配置php.ini
extension=php_oci8_12c.dll
extension=php_pdo_oci.dll
去掉分号,然后重启服务(Apache or IIS)
查看是否开启
二、composer 添加第三方的组件 yajra/laravel-oci8
1.换源
composer config -g repo.packagist composer https://packagist.phpcomposer.com
2.安装
composer require yajra/laravel-oci8 -vvv
三、使用第三方组件
1.修改在config文件夹下的database.php
修改:’default’ => env(‘DB_CONNECTION’, ‘oracle’),
增加如下:
'oracle' => [ 'driver' => 'oracle', 'tns' => env('DB_TNS', ''), 'host' => env('DB_HOST', '10.0.101.177'), 'port' => env('DB_PORT', '1521'), 'database' => env('DB_DATABASE', 'MPPAYUAT'), 'username' => env('DB_USERNAME', 'payment'), 'password' => env('DB_PASSWORD', 'payment'), 'charset' => env('DB_CHARSET', 'AL32UTF8'), 'prefix' => env('DB_PREFIX', ''), 'prefix_schema' => env('DB_SCHEMA_PREFIX', ''), ],
2.修改ConnectionFactory.php中的createConnector函数和createConnection函数
(文件在vendor/laravel/framework/src/illuminate/Database/Connectors/ConnectionFactory.php)
2.0. ConnectionFactory类引用以下声明
use YajraOci8ConnectorsOracleConnector; use YajraOci8Oci8Connection;
2.1.createConnector函数:
case 'sqlsrv': return new SqlServerConnector; case 'oracle': return new OracleConnector;
2.2createConnection函数:
case 'sqlsrv': return new SqlServerConnection($connection, $database, $prefix, $config); case 'oracle': return new Oci8Connection($connection, $database, $prefix, $config);
3. 修改config/app.php
在providers里面增加
YajraOci8Oci8ServiceProvider::class,
4. 修改 processInsertGetId 函数
(在vendor/yajra/laravel-oci8/src/Oci8/Query/processors/OracleProcessor.php)
$statement->bindParam($parameter, $id, PDO::PARAM_STR, 20);//PDO::PARAM_STR 主键的 数据类型
至此已经完成了Laravel对Oracle的支持配置
四、测试
参考: