PHP oci_connect() TNS:无法解析连接标识符 (ORA-12154)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20345605/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
PHP oci_connect() TNS:could not resolve the connect identifier (ORA-12154)
提问by user2990252
I'm testing some PHP code on Ubuntu server and oracle database connection is checked by the "tnsping" command
我正在 Ubuntu 服务器上测试一些 PHP 代码,并且通过“tnsping”命令检查了 oracle 数据库连接
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
但是,PHP 中的 oci_connect 函数显示如下警告
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
警告:oci_connect():ORA-12154:TNS:无法解析在 /usr/local/ipm5/wui/manager/123.bih 中指定的连接标识符第 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
当然,OCI8 已启用(通过 phpinfo 检查)并且一些环境(PATH, ORACLE_BASE, ORACLE_HOME, ORACLE_SID, TNS_ADMIN, LD_LIBRARY_PATH)变量被设置为/etc/bash.bashrc
do anyone recommend?? what the problem is.
有人推荐吗??问题是什么。
回答by ray
instead of ORCL, you may want to put the whole string in oci_connect
而不是 ORCL,您可能希望将整个字符串放在 oci_connect 中
(DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.3.14)(PORT = 1521)) (CONNECT_DATA = (SERVICE_NAME = ORCL) (SID = ORCL)))
PHP code:
PHP代码:
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
检查 phpinfo() 输出“环境”部分,如果你没有 ORACLE_HOME、TNS_ADMIN,你需要将它们提供给你的 PHP 运行环境,对于用 php_module 编译的 apache
export ORACLE_HOME=/path/to/oracle_home
export TNS_ADMIN=/path/to/tns_admin
apachectl start
for php-cgi or php-fpm
对于 php-cgi 或 php-fpm
export ORACLE_HOME=/path/to/oracle_home
export TNS_ADMIN=/path/to/tns_admin
/script/to/start/fpm
回答by afilina
This can also happen when using a remote database that is unreachable, or requires a VPN connection to be accessed.
当使用无法访问的远程数据库或需要访问 VPN 连接时,也会发生这种情况。

