/ 中存储网

Linux下使用PHP远程连接Oracle

2014-02-27 00:00:00 来源:中存储网

PHP远程连接Oracle需要OCI包,这个包由oracle提供,可以直接安装Oracle的InstantClient来得到这个包
下载地址http://www.oracle.com/technology/tech/oci/instantclient/instantclient.html

安装很简单
rpm -Uvh oracle-instantclient-basic-10.2.0.3-1.i386.rpm
rpm -Uvh oracle-instantclient-devel-10.2.0.3-1.i386.rpm

安装完成后,可以在/usr/lib/oracle 看到安装的库文件

之后需要重新编译php,加上--with-oci8=share,instantclient,/usr/lib/oracle/10.2.0.3/client/lib参数,如下:
./configure --with-mysql --with-apxs2=/usr/local/apache2/bin/apxs--with-oci8=share,instantclient,/usr/lib/oracle/10.2.0.3/client/lib

测试代码:

<?php
$conn = OCILogon('username','password','192.168.1.2/test');
if (!$conn) {
$e = oci_error();
print htmlentities($e['message']);
exit;
}
else
{
echo "Successfully connected to Oracle!n";
        ocilogoff($conn);
}
?>

一些相关链接:
http://www.oracle.com/technology/pub/notes/technote_php_instant.html

还有就是php中oci的编译参数,可以看php原代码目录中ext/oci8的README,里面有解释。