天天看点

php安装oci8扩展使用oci8链接错误解决办法,如下:注意:操作系统为centos,查看主机名的命令为hostname

转载: 五环小胖子的博客

centos下安装oci扩展,远程访问oracle。

[ 百度网盘 ]

提取码:u67a

下载完成后:

  • oracle-instantclient12.1-basic-12.1.0.2.0-1.x86_64.rpm
  • oracle-instantclient12.1-devel-12.1.0.2.0-1.x86_64.rpm
  • oracle-instantclient12.1-sqlplus-12.1.0.2.0-1.x86_64.rpm

开始安装

$ rpm -ivh oracle-instantclient12-basic--x86_64.rpm
$ rpm -ivh oracle-instantclient12-devel--x86_64.rpm
$ rpm -ivh oracle-instantclient12-sqlplus--x86_64.rpm
$ echo "/usr/lib/oracle/12.1/client64/lib" > /etc/ld.so.conf.d/oracle_client.conf
$ /sbin/ldconfig
           

安装oci8

安装前请注意版本,目前2.1.0是php7编译的,若php版本在5.2~5.6之间,请选择2.0.10版本

以下是安装脚本:

$ wget http://pecl.php.net/get/oci8-.tgz
$ tar -xf oci8-.tgz
$ cd oci8-
$ phpize
$ ./configure --with-oci8=shared,instantclient,/usr/lib/oracle//client64/lib --with-php-config=/usr/bin/php-config
$ make
$ make test
$ make install
           

配置

oci8安装成功后,会在/usr/lib64/php/modules/目录下生成oci8.so文件 然后在php.ini中添加extension=oci8.so配置 执行php -m后查看扩展是否加载

若成功后,用脚本测试连接

<?php
$conn = oci_connect('用户名', '密码', '远程数据库名(//192.168.1.157/orcl)');
if (!$conn) {
  $e = oci_error();
  print htmlentities($e['message']);
  exit;
}else {
  echo "连接oracle成功!";
}
?>
           

使用oci8链接错误

初次使用oci8链接oracle时,遇见这个错误:

ORA-: could not generate unique server group name
           

解决办法,如下:

修改/etc/sysconfig/network,如果没有就创建一下,添加代码HOSTNAME=你的主机名

修改/etx/hosts,添加代码127.0.0.1 你的主机名

service network restart 重启一下服务

注意:操作系统为centos,查看主机名的命令为hostname