Centos 6 PHP OCI8扩展无法正常工作(未定义函数oci_connect())
我正在使用Centos 6 64位操作系统.最近我已经用PHP安装了OCI8扩展.完成所有配置后,我尝试执行oci_connect函数以远程连接Oracle数据库.
I am using Centos 6 64 bit OS. Recently i have installed OCI8 extension with php. After making all configuration i tried to execute the function oci_connect to connect with a Oracle Database remotely.
不幸的是我遇到了这个错误:
Unfortunately i got this error:
Fatal error: Call to undefined function oci_connect() in /var/www/html/index.php on line 5
我已经这样安装了oci8:
OCI8
OCI8
使用梨下载OCI8源码
Download the OCI8 source using pear
$ pear download pecl/oci8
$ tar -xvf oci8-1.4.9.tgz
$ cd oci8-1.4.9
构建并安装扩展程序.
$ phpize
$ ./configure --with-oci8=shared,instantclient,/usr/lib/oracle/11.2/client64/lib
$ make
$ sudo make install
要启用扩展,请在/etc/php.d中添加一个名为oci8.ini的文件,其中包含 此内容:
To enable the extension, add a file named oci8.ini in /etc/php.d with this content:
extension=oci8.so
验证它是否已成功安装.
Validate that it was successfully installed.
$ php -i | grep oci8
$ php -i | grep oci8
您应该会看到类似这样的内容:
You should see something like this:
/etc/php.d/oci8.ini,
oci8
oci8.connection_class => no value => no value
oci8.default_prefetch => 100 => 100
oci8.events => Off => Off
oci8.max_persistent => -1 => -1
oci8.old_oci_close_semantics => Off => Off
oci8.persistent_timeout => -1 => -1
oci8.ping_interval => 60 => 60
oci8.privileged_connect => Off => Off
oci8.statement_cache_size => 20 => 20
参考: http ://shiki.me/blog/installing-pdo_oci-and-oci8-php-extensions-on-centos-6-4-64bit/
我想提到的是,安装开始时显示的消息为:Instantclient,/../../来放置路径.我什么也没给,只是按回车键.是我无法连接到Oracle的问题吗?
I would like to mention that when the installation started is message was display something like: instantclient, /../../ to PUT THE PATH. I didn't give anything, just pressed enter. Is it the issue that i can't connect to Oracle ?
急需您的帮助.
谢谢
我设法解决了问题.实际的问题是环境库未加载.所以我已经通过PHP手动加载了oracle环境.
I have managed to solve problem. Actually the problem was the the environment library was not loaded. so i have loaded the environment of oracle manually via PHP .
这是我的代码:
> if (!$conn):
> /// INCLUDING ORACLE_HOME MANUALLY
> putenv("ORACLE_HOME=/u01/app/oracle/product/11.2.0/dbhome_1/");
> // INCLUDING LD_LIBRARY_PATH MANUALLY
> putenv("LD_LIBRARY_PATH=/u01/app/oracle/product/11.2.0/dbhome_1/lib:/lib:/usr/lib:/lib:/usr/lib:/usr/local/lib");
>
> $conn = "(DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = xxx.xxx.xxx.xxx)(PORT = 1521)))
> (CONNECT_DATA = (SERVICE_NAME = data)))";
> $conn = oci_pconnect("username", "password", $conn);
> endif;
> if($conn):
> return $conn;
> endif;
> if(!$conn):
> redirect('login');
> endif;
> }
希望对大家有帮助
谢谢