环境,mysql+php+apache+rhas4,没有安装oracle,如果安装了oracle服务器,则不需要做文件的链接,但是目录的链接是需要的。
1、先到oracle网站下载instantclient,下载了相应的6个文件,unzip解压。
2、instantclient目录 /usr/source/instantclient/instantclient_10_2/,完成后作一些链接配置
完成后如下:
-r--r--r-- 1 root root 1600090 2006-11-16 classes12.jar
-rwxrwxr-x 1 root root 67053 2006-11-16 genezi
-r--r--r-- 1 root root 1525 2006-11-16 glogin.sql
lrwxrwxrwx 1 root root 56 6月 13 11:26 include -> /usr/source/instantclient/instantclient_10_2/sdk/include
lrwxrwxrwx 1 root root 2 6月 13 12:02 lib32 -> ./
lrwxrwxrwx 1 root root 17 6月 13 12:19 libclntsh.so -> libclntsh.so.10.1
-rwxrwxr-x 1 root root 18825267 2006-11-16 libclntsh.so.10.1
-r-xr-xr-x 1 root root 27822 2006-11-16 libheteroxa10.so
-r-xr-xr-x 1 root root 5486009 2006-11-16 libnnz10.so
lrwxrwxrwx 1 root root 15 6月 13 12:19 libocci.so -> libocci.so.10.1
-rwxrwxr-x 1 root root 1398088 2006-11-16 libocci.so.10.1
-rwxrwxr-x 1 root root 72480394 2006-11-16 libociei.so
-r-xr-xr-x 1 root root 120135 2006-11-16 libocijdbc10.so
-r-xr-xr-x 1 root root 1434235 2006-11-16 libsqlplusic.so
-r-xr-xr-x 1 root root 1057777 2006-11-16 libsqlplus.so
lrwxrwxrwx 1 root root 16 6月 13 12:20 libsqora.so -> libsqora.so.10.1
-rwxrwxr-x 1 root root 772395 2006-11-16 libsqora.so.10.1
-r--r--r-- 1 root root 21548 2006-11-16 ODBC_IC_Readme_Linux.html
-r-xr-xr-x 1 root root 91881 2006-11-16 ODBCRelnotesJA.htm
-r-xr-xr-x 1 root root 58416 2006-11-16 ODBCRelnotesUS.htm
-r--r--r-- 1 root root 3457 2006-11-16 odbc_update_ini.sh
-r--r--r-- 1 root root 1545954 2006-11-16 ojdbc14.jar
-r--r--r-- 1 root root 1645114 2006-11-16 orai18n.jar
drwxrwxr-x 4 root root 4096 2006-11-16 sdk
-r-xr-xr-x 1 root root 8867 2006-11-16 sqlplus
如果上面没有做文件的链接,在make的时候会出现
/usr/bin/ld: cannot find -lclntsh
collect2: ld returned 1 exit status
make: *** [pdo_oci.la] 错误 1
3、到php的安装目录下的ext/pdo_oci,先运行程序phpize生成configure,然后直接运行
./configure --with-php-config=/usr/local/php521/bin/php-config --with-pdo-oci=/usr/source/instantclient/instantclient_10_2/
或则
./configure --with-php-config=/usr/local/php521/bin/php-config --with-pdo-oci=instantclient,/usr/source/instantclient/instantclient_10_2/,10.2.0.3
make;
将instantclient的include加入到/etc/ld.so.conf
ldconfig;
make install
4、生成pdo_oci.so,复制该文件到指定的extended_dir中,在php.ini中加入
extension=pdo_oci.so;
5、重启apache
6、测试程序
$tns = "
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = xxx.xxx.xxx.xxx)(PORT = 1521))
)
(CONNECT_DATA =
(SERVICE_NAME = orcl)
)
)
";
$db_username = "user";
$db_password = "pass";
try{
$conn = new PDO("oci:dbname=".$tns,$db_username,$db_password);
echo "connected successful";
}catch(PDOException $e){
echo ($e->getMessage());
}
?>
正式使用后,发现显示字符集有问题,使用的字符集是zh_cn.utf8
因此需要做一些设置,如下:
先修改环境变量
export NLS_LANG='SIMPLIFIED CHINESE'_CHINA.UTF8
然后连接的时候再做如下修改
$conn = new PDO("oci:dbname=".$tns.";charset=AL32UTF8",$db_username,$db_password);
阅读(4588) | 评论(1) | 转发(0) |