昊 2019-06-27
最近因为项目研究了一下PHP集成Oracle,虽然这个组合很奇葩,但万一用到请勿采坑~
下载 http://www.oracle.com/technet...
oracle-instantclient12.2-basic-12.2.0.1.0-1.x86_64.rpm
oracle-instantclient12.2-devel-12.2.0.1.0-1.x86_64.rpm
PS: 两个都必须安装,devel版本就是SDK
安装
# rpm -i oracle-instantclient12.2-basic-12.2.0.1.0-1.x86_64.rpm # rpm -i oracle-instantclient12.2-devel-12.2.0.1.0-1.x86_64.rpm
安装成功会生成如下目录,64位系统必须软连接成旧版(否则编译报版本不支持的错,应该是历史问题,坑1)
# ln /usr/lib/oracle/12.2 /usr/lib/oracle/10.2.0.1 # ln /usr/include/oracle/12.2 /usr/include/oracle/10.2.0.1
添加环境变量
# vi etc/profile
加入
export ORACLE_HOME=/usr/lib/oracle/11.2/client64/ export LD_LIBRARY_PATH=/usr/lib/oracle/11.2/client64:$LD_LIBRARY_PATH export NLS_LANG="AMERICAN_AMERICA.AL32UTF8"
生效
# source /etc/profile
下载最新的包
oci8-2.1.8.tgz和PDO_OCI-1.0.tgz
编译安装oci8
# tar -zxf oci8-2.1.8.tgz # cd oci8-2.1.8 # phpize # ./configure --with-php-config=/usr/local/php/bin/php-config --with-oci8=shared,instantclient,/usr/lib/oracle/12.2/client64/lib # make # make install
生成oci8.so即成功
编译安装pdo_oci
# tar -zxf PDO_OCI-1.0.tgz # cd PDO_OCI-1.0 # phpize # ./configure --with-php-config=/usr/local/php/bin/php-config --with-pdo-oci=instantclient,/usr,10.2.0.1 # make # make install
生成pdo_oci.so即成功
具体方式根据PHP环境而定,我的环境不需要改变so文件路径,使用生成的默认路径即可,只需要添加Additional .ini files到/usr/local/php/etc/php.d/,重启生效
确认生效状态
# php -m | grep -e oci8 -e PDO_OCI oci8 PDO_OCI
大功告成
PS
由于编译安装下载的pdo_oci总是报错(坑2),于是到php.net下载了对应版本的php(比如:http://us1.php.net/get/php-7....),拷贝ext目录下的pdo_oci编译安装,步骤同上。
<?php. if (!empty($_POST)) {. $data1 = $_POST["data1"];$data2 = $_POST["data2"];$fuhao = $_POST["fuh