本文介绍了PHP oci_connect()TNS:无法解析连接标识符(ORA-12154)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在Ubuntu服务器上测试一些PHP代码,并且通过"tnsping"命令检查了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)

但是,PHP中的oci_connect函数显示如下警告

But, oci_connect function in PHP shows an warning like as

当然,启用了OCI8(通过phpinfo检查),并将某些环境(PATHORACLE_BASEORACLE_HOMEORACLE_SIDTNS_ADMINLD_LIBRARY_PATH)变量设置为/etc/bash.bashrc

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.

推荐答案

而不是ORCL,您可能希望将整个字符串放入oci_connect

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代码:

oci_connect($username, $password, '(DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.3.14)(PORT = 1521)) (CONNECT_DATA = (SERVICE_NAME = ORCL) (SID = ORCL)))');

检查phpinfo()输出的环境"部分,如果您没有ORACLE_HOME,TNS_ADMIN,则需要将其提供给您的PHP运行环境,用php_module编译的Apache

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

对于php-cgi或php-fpm

for php-cgi or php-fpm

export ORACLE_HOME=/path/to/oracle_home
export TNS_ADMIN=/path/to/tns_admin
/script/to/start/fpm

这篇关于PHP oci_connect()TNS:无法解析连接标识符(ORA-12154)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-23 13:09
查看更多