zoukankan      html  css  js  c++  java
  • Laravel框架连接Oracle数据库

    windows 系統

    一、PHP开启oci8

    1.下载 Oracle Instant Client

    下载地址:https://www.oracle.com/technetwork/database/database-technologies/instant-client/downloads/index.html

    下载后解压到系统盘(本人解压到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的支持配置

    四、测试

    参考:

    https://blog.csdn.net/q393364227/article/details/78458690

    https://www.meiwen.com.cn/subject/imfljqtx.html

  • 相关阅读:
    网络流量监控工具iftop
    CentOS6.X安装vsftpd服务
    CentOS 6.x版本升级Mysql
    CentOS 5.x版本升级Mysql
    CentOS 5.x版本升级PHP
    CentOS 6.X版本升级PHP
    Spring bean configuration inheritance
    cannot load such file -- openssl
    第八章、Linux 磁盘与文件系统管理
    Laravel Configuration
  • 原文地址:https://www.cnblogs.com/clubs/p/12568613.html
Copyright © 2011-2022 走看看