后半部分centos环境已测试通过
一、设置php.ini
php.ini中开启相关扩展:extension=php_oci8_12c.dll、extension=php_pdo_oci.dll
如果不是集成环境,需要自己去官网自行下载放到php/ext/目录下 https://pecl.php.net/package/oci
二、下载并配置Oracle Instant Client
1.查看连接oracle数据库版本号:
select * from v$version;
2.oracle官网选择并下载合适的自己oracle版本的包
https://www.oracle.com/database/technologies/instant-client/downloads.html
解压到任意目录
3.配置win系统环境变量
右击电脑 -> 属性 -> 高级系统设置 -> 环境变量 -> 新建
1)变量名:NLS_LANG
变量值:SIMPLIFIED CHINESE_CHINA.ZHS16GBK
2)变量名:ORACLE_HOME
变量值:F:\phpStudy\PHPTutorial\instantclient_18_5
3)变量名:TNS_ADMIN
变量值:F:\phpStudy\PHPTutorial\instantclient_18_5
修改path变量:增加F:\phpStudy\PHPTutorial\instantclient_18_5
三、验证
重启web服务,nginx或apache,集成环境有时候需要多重启几次
$db_user = "user";
$db_pass = "pass";
$conn = oci_connect($db_user,$db_pass,"127.0.0.1/oral");
$sql = "SELECT FDATA FROM db.table WHERE FID='0O7lLrGCSAa2vNjQW5jpWQdY8J8='";
$result_rows = oci_parse($conn, $sql);
$row_count = oci_execute($result_rows, OCI_DEFAULT);
$result = oci_fetch_array($result_rows, OCI_ASSOC);
$arr['FDATA'] = oci_result($result_rows,'FDATA');
$arr['FDATA'] = $arr['FDATA']->load();
var_dump($arr);die;
四、兼容64位Navicat
1.下载64位Oracle Instant Client
2.解压放到另外一个目录下,比如:F:\instantclient_18_5
3.工具 -> 选项 -> 环境 -> OCI环境(选择64位解压包oci.dll)
4.重启
环境介绍:Centos、7.3.19
一、安装oracle rpm包
1.下载
wget https://download.oracle.com/otn_software/linux/instantclient/185000/oracle-instantclient18.5-basic-18.5.0.0.0-3.x86_64.rpm
wget https://download.oracle.com/otn_software/linux/instantclient/185000/oracle-instantclient18.5-devel-18.5.0.0.0-3.x86_64.rpm
2.安装
rpm -i oracle-instantclient18.5-basic-18.5.0.0.0-3.x86_64.rpm
rpm -i oracle-instantclient18.5-devel-18.5.0.0.0-3.x86_64.rpm
二、编译安装pdo_oci和oci8
1.下载
特别说明:pdo_oci包必须和php版本一致,所以建议下载php版本,用ext/pdo_oci包进行安装
wget --no-check-certificate https://www.php.net/distributions/php-7.3.19.tar.gz
wget --no-check-certificate https://pecl.php.net/get/oci8-2.2.0.tgz
2.安装
安装oci8
tar -zxvf oci8-2.2.0.tgz
cd oci8-2.2.0
phpize
./configure --with-php-config=/usr/local/php-7.3.19/bin/php-config --with-oci8=shared,instantclient,/usr/lib/oracle/18.5/client64/lib
make
make install
安装pdo_oci
#安装pdo_oci
tar -zxvf tar -zxvf php-7.3.19.tar.gz
cd php-7.3.19/ext/
cp -r pdo_oci/ /tmp/
cd /tmp/pdo/oci/
phpize
./configure --with-php-config=/usr/local/php-7.3.19/bin/php-config --with-pdo-oci=instantclient,/usr/lib/oracle/11.2/client64/lib
make
make install
vim /usr/local/php-7.3.19/etc/php.ini #加入oci8.so和pdo_oci.so
export LD_LIBRARY_PATH=$ORACLE_HOME/lib #有时会因为缺少libnnz11.so报错,执行这条命令即可
3.验证
php -m