Piba Posted May 7, 2008 Share Posted May 7, 2008 Hello guys, Ok, i'm working on php/mysql but now i want to deal with oracle (on other server), So i installed instantclient-sqlplus-win32 for oracle, and when i open phpinfo page, the oci8 is enabled But my problem is when i connect to db, this error is show up ORA-12154: TNS:could not resolve the connect identifier specified My coonect code: <?php // try connecting to the database $conn = oci_connect('username', 'password', 'host'); // check for any errors if (!$conn) { $e = oci_error(); print htmlentities($e['message']); exit; } // else there weren't any errors else { echo 'I am an Oracle mack daddy.'; } ?> I checked from the file tnsname.ora But when i searched on google to find solution, i read that it should be a file named sqlnet.ora And i don't have this file... Is this my problem?? Shall i got both sqlnet.ora and tnsname.ora files?? Please i need help as soon as possible Thanks Quote Link to comment https://forums.phpfreaks.com/topic/104520-solved-ora-12154-tnscould-not-resolve-the-connect-identifier-specified/ Share on other sites More sharing options...
gizmola Posted May 9, 2008 Share Posted May 9, 2008 The tnsnames.ora file is like DNS for oracle instances. Basically what that error is telling you is that it can't convert the oracle instance name you're providing to a Server/IP/Port combination. The sqlnet.ora file allows you to configure sql*net which is oracle's network protocol. Needless to say, these are 2 totally seperate things. With that said, you probably want to try and use the oracle connection string that allows you to circumvent the need for a tnsnames.ora file. There's a nice summary blog post here: http://alisonatoracle.blogspot.com/2006/02/oracle-database-connection-strings-in.html Quote Link to comment https://forums.phpfreaks.com/topic/104520-solved-ora-12154-tnscould-not-resolve-the-connect-identifier-specified/#findComment-536907 Share on other sites More sharing options...
Piba Posted May 11, 2008 Author Share Posted May 11, 2008 Hi gizmola, Thanks for replying, i read the site you suggested, it's really helpful.. But my problem now as the following: When i write in the "run": C:\Program Files\instantclient11 sqlplus username/password@db It response and oracle information was showup.. BUT...when i try to access database through php code, the same error is appeared So, is the problem from my code, or something inside the tnsname.ora? or the problem from the other server (which have oracle database)?? And BTW, i tried all three ways in the website with no respone Thanks, Piba Quote Link to comment https://forums.phpfreaks.com/topic/104520-solved-ora-12154-tnscould-not-resolve-the-connect-identifier-specified/#findComment-538177 Share on other sites More sharing options...
gizmola Posted May 19, 2008 Share Posted May 19, 2008 Piba, Can you tnsping the database from that server? It seems like you have a problem with your connect string. If you can construct a valid tnsnames.ora entry and tnsping it, then that should allow you to connect using the verbose format. Quote Link to comment https://forums.phpfreaks.com/topic/104520-solved-ora-12154-tnscould-not-resolve-the-connect-identifier-specified/#findComment-545073 Share on other sites More sharing options...
seche Posted March 18, 2009 Share Posted March 18, 2009 Sorry to bring back an old thread but I get the same error message "ORA-12154: TNS:could not resolve the connect identifier specified" When I simply try to connect in my php script using a SID. Basically I can connect fine with sqlplus using the sid. I can connect with php if I supply the full string. But when I use the alias/SID with php it gives me this error. I am 90% sure php see's the tnsnames.ora file because I get a different error if I use SERVICE_NAME instead of SID in the connection string. I am using Red Hat Enterprise Linux 5, Apache 2.2 and PHP 5.2.9. Basically trying to setup a new server. I use this script to setup my ENV Variables: #!/bin/sh service httpd stop LD_LIBRARY_PATH=/usr/lib/oracle/11.1/client/lib:${LD_LIBRARY_PATH} TNS_ADMIN=/home NLS_LANG=AMERICAN_AMERICA.UTF8 export LD_LIBRARY_PATH TNS_ADMIN NLS_LANG echo Starting Apache service httpd start Appreciate the help. Thanks Quote Link to comment https://forums.phpfreaks.com/topic/104520-solved-ora-12154-tnscould-not-resolve-the-connect-identifier-specified/#findComment-787946 Share on other sites More sharing options...
seche Posted March 19, 2009 Share Posted March 19, 2009 figured out php did not care about TNS_ADMIN and put a copy of the sqlnet.ora and tnsnames.ora in the $ORACLE_HOME/network/admin folder that I had to create. Hope this saves trouble for someone else Cheers! Quote Link to comment https://forums.phpfreaks.com/topic/104520-solved-ora-12154-tnscould-not-resolve-the-connect-identifier-specified/#findComment-788499 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.