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
当使用无法访问的远程数据库或需要访问 VPN 连接时,也会发生这种情况。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.