Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
281 views
in Technique[技术] by (71.8m points)

oracle - Centos 6 PHP OCI8 extention is not working (Undefined function oci_connect())

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  

I have installed oci8 like this:

OCI8

Download the OCI8 source using pear

$ pear download pecl/oci8
$ tar -xvf oci8-1.4.9.tgz
$ cd oci8-1.4.9

Build and install the extension.

$ phpize 
$ ./configure --with-oci8=shared,instantclient,/usr/lib/oracle/11.2/client64/lib 
$ make 
$ sudo make install

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

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

Ref: http://shiki.me/blog/installing-pdo_oci-and-oci8-php-extensions-on-centos-6-4-64bit/

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 ?

Need your help badly.

Thanks

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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 .

Here is my code:

>     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;
>             }

Hope that it will help everyone

Thanks,


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...