使用的安装包:
1 cronolog-1.6.2.tar.gz
2httpd-2.0.59.tar.gz
3instantclient-basic-linux32-10.2.0.2-20060331.zip
4instantclient-sdk-linux32-10.2.0.2-20060331.zip
5libmcrypt-2.5.7.tar.gz
6mhash-0.9.7.1.tar.gz
7mysql-3.23.58.tar.gz
8php-4.4.4.tar.gz
参考文档:
- 为 Linux 和 Windows 安装 PHP 和 Oracle 10g Instant Client
- Connecting to Oracle10g from PHP using OCI-8 (Linux)
与文档有出处的地方:
- otn上只能下到zip格式的oracle 10g instant client basic和sdk包。解压缩后,全部放到instantclient_10_2目录下。
[root@localhost sdk]# ls -l ..
total 115948
-r--r--r-- 1 root root 1594191 Feb 5 2006 classes12.jar
-rwxrwxr-x 2 root root 18774535 Feb 5 2006 libclntsh.so
-rwxrwxr-x 2 root root 18774535 Feb 5 2006 libclntsh.so.10.1
-r-xr-xr-x 1 root root 5623929 Feb 5 2006 libnnz10.so
-rwxrwxr-x 1 root root 1398088 Feb 5 2006 libocci.so.10.1
-rwxrwxr-x 1 root root 70690282 Feb 5 2006 libociei.so
-r-xr-xr-x 1 root root 119919 Feb 5 2006 libocijdbc10.so
-r--r--r-- 1 root root 1540457 Feb 5 2006 ojdbc14.jar
drwxr-xr-x 4 root root 4096 Oct 17 04:27 sdk
[root@localhost sdk]# ls -l
total 324
drwxr-xr-x 2 root root 4096 Oct 17 04:27 demo
drwxr-xr-x 2 root root 4096 Oct 17 04:27 include
-r-xr-xr-x 1 root root 346 Oct 17 04:27 ott
-rw-r--r-- 1 root root 298274 Oct 17 04:27 ottclasses.zip
- php4.4.4已经提供了--with-oci8-instant-client参数的支持,同时修复了相关补丁,因此,文档中为php打补丁、重建“configure”脚本的步骤可以省略。
环境变量:
- 在LD_LIBRARY_PATH中添加oracle 10g instant client的路径。
export LD_LIBRARY_PATH=/www/server/instantclient_10_2/:${LD_LIBRARY_PATH}
- 设置TNS_ADMIN为oracle tnsname.ora文件所在目录。
export TNS_ADMIN=/u01/app/oracle/product/10g/network/admin/
编译脚本:
./configure \
--prefix=/www/server/php-4.4.4 \
--with-apxs2=/www/server/httpd-2.0.59/bin/apxs \
--with-mysql=/www/server/mysql-3.23.58 \
--with-mcrypt=/www/server/libmcrypt-2.5.7 \
--with-mhash=/www/server/mhash-0.9.7.1 \
--with-gd --with-zlib \
--with-oci8-instant-client=/www/server/instantclient_10_2
注:需要使用ln命令为libclntsh.so.10.1创建一个名为
libclntsh.so的连接,否则在configure过程中将会出现error:Link xxxx not found的错误。(
http://forums.oracle.com/forums/thread.jspa?messageID=1203218�)
测试:
- 安装成功的话,在phpinfo()信息中可以看到相应信息
OCI8 Support enabled
Revision $Revision: 1.183.2.18.2.3 $
Oracle Version 10.1
Compile-time ORACLE_HOME /www/server/instantclient_10_2
Libraries Used no value
- 测试代码
1 <?php
2 $conn = OCILogon("username", "password", "//127.0.0.1:1521/sid");
3 $query = 'select table_name from user_tables';
4 $stid = OCIParse($conn, $query);
5 OCIExecute($stid, OCI_DEFAULT);
6
7 while ($succ = OCIFetchInto($stid, $row)) {
8 foreach ($row as $item) {
9 echo $item." ";
10 }
11 echo "<br>\n";
12 }
13 OCILogoff($conn);
14 ?>