此处采用的docker容器环境是php:7.2
 
1. 打开Oracle官网下载oracle客户端
https://www.oracle.com/database/technologies/instant-client/linux-x86-64-downloads.html
下载basic 和 sdk包

 

 

 

 

 

 

2.解压和配置环境变量
解压到目录 /oracle11/instantclient下 作为根目录
export ORACLE_HOME=/oracle11/instantclient/client64
export LD_LIBRARY_PATH=$ORACLE_HOME/lib
 
3. unzip ...basic 包,和sdk包 (此处的sdk包会放入basic生成的instantclient文件夹里面)
重命名为instantclient文件夹
4.创建三个.so文件的软链,并且复制libnnz11.so到/usr/lib/下
ln -s libclntsh.so.11.1 libclntsh.so
ln -s libocci.so.11.1 libocci.so
ln -s libnnz11.so libnnz.so
cp /oracle11/instantclient/libnnz11.so /usr/lib/
安装libaio扩展
apt-get update
apt-get install libaio*
 
5.编译和安装 oci8和pdo_oci
//编译
docker-php-ext-configure oci8 --with-oci8=instantclient,/oracle11/instantclient
docker-php-ext-configure pdo_oci --with-pdo-oci=instantclient,/oracle11/instantclient
//安装
docker-php-ext-install oci8
docker-php-ext-install pdo_oci
 
6.最后在php.ini添加扩展支持
extension=oci8.so
extension=pdo_oci.so
 
 
7.执行demo文件测试下

<?php

//创建连接 connect_data 看实际情况可选择不填写

$conn = oci_connect('test', '123', '(DESCRIPTION=
(ADDRESS_LIST=
(ADDRESS=(PROTOCOL=TCP)
(HOST=127.0.0.1)(PORT=1521)
)
)
(CONNECT_DATA =
(SERVICE_NAME = orcl)
)
)');
$select = "select * from all_users";
$result_rows = oci_parse($conn, $select);
$row_count = oci_execute($result_rows, OCI_DEFAULT); 
while($row = oci_fetch_array($result_rows, OCI_RETURN_NULLS)){
var_dump($row);
}

 

posted on 2021-02-01 16:18  cyqAkin  阅读(652)  评论(0编辑  收藏  举报