I'm testing some PHP code on Ubuntu server and oracle database connection is checked by the "tnsping" command
Used TNSNAMES adapter to resolve the alias
Attempting to contact (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.3.14)(PORT = 1521)) (CONNECT_DATA = (SERVICE_NAME = ORCL) (SID = ORCL)))
OK (10 msec)
But, oci_connect function in PHP shows an warning like as
Warning: oci_connect(): ORA-12154: TNS:could not resolve the connect identifier specified in /usr/local/ipm5/wui/manager/123.bih on line 6 2
of course, the OCI8 is enabled(checked via phpinfo) and some environment(PATH
,ORACLE_BASE
,ORACLE_HOME
,ORACLE_SID
,TNS_ADMIN
,LD_LIBRARY_PATH
) variables are set into /etc/bash.bashrc
do anyone recommend?? what the problem is.
instead of ORCL, you may want to put the whole string in oci_connect
(DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.3.14)(PORT = 1521)) (CONNECT_DATA = (SERVICE_NAME = ORCL) (SID = ORCL)))
PHP code:
oci_connect($username, $password, '(DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.3.14)(PORT = 1521)) (CONNECT_DATA = (SERVICE_NAME = ORCL) (SID = ORCL)))');
check phpinfo() output "Environment" part, if you don't have ORACLE_HOME, TNS_ADMIN, you need to make those available to your PHP running environment, for apache compiled with php_module
export ORACLE_HOME=/path/to/oracle_home
export TNS_ADMIN=/path/to/tns_admin
apachectl start
for php-cgi or php-fpm
export ORACLE_HOME=/path/to/oracle_home
export TNS_ADMIN=/path/to/tns_admin
/script/to/start/fpm
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With