Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP oci_connect() TNS:could not resolve the connect identifier (ORA-12154)

Tags:

php

oracle

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.

like image 466
user2990252 Avatar asked Dec 03 '13 07:12

user2990252


1 Answers

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
like image 131
ray Avatar answered Sep 23 '22 01:09

ray