PHP oci_connect () TNS: Could not resolve connection identifier (ORA-12154)

I am testing some PHP code on an Ubuntu server, and the 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 the oci_connect function in PHP shows a warning like

Warning: oci_connect (): ORA-12154: TNS: could not resolve the connection identifier specified in / usr / local / ipm 5 / wui / manager / 123.bih on line 6 2

of course, OCI8 is enabled (checked via phpinfo), and some environment variables ( PATH , ORACLE_BASE , ORACLE_HOME , ORACLE_SID , TNS_ADMIN , LD_LIBRARY_PATH ) are set to /etc/bash.bashrc

would anyone recommend ??? what is the problem.

+6
source share
1 answer

instead of ORCL, you can put the whole line 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 () the output part of "Environment", if you do not have ORACLE_HOME, TNS_ADMIN, you need to make them available for your PHP working 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 
+12
source

Source: https://habr.com/ru/post/959221/


All Articles