• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2203
  • Last Modified:

PHP setting Oracle Connection : Oracle: Connection Failed: ORA-12154: TNS:could not resolve service name

Helo Evreyone... I am novice when it comes to PHP.
In need to access an Oracle database from a PHP form ..(queries will come later but I am unable to create a connection in the first place)

I have programmed iin Java JDBC before and the connection string is as below


And from The Oracle client(Toad) I connect by using the  

I tried this with PHP but failed to connect
$connection = ora_logon("username@server.db","password");

if ($connection == false){
  echo Ora_ErrorCode($connection).": ".Ora_Error($connection)."<BR>";

$cursor = Ora_Open ($connection);
if ($cursor == false){
  echo Ora_ErrorCode($connection).": ".Ora_Error($connection)."<BR>";

Ora_Commit ($connection);
Ora_Close ($cursor);
Ora_Logoff ($connection);

Thanks for your time
1 Solution
UmeshMySQL Principle Technical Support EngineerCommented:
micro_learnerAuthor Commented:
Hello ... I figured out that the earlier error was a TNSoraname error.I resolved it but I still get the error

Warning: Oracle: Connection Failed: Error while trying to retrieve text for error ORA-12514 in /home/i/html/test2.php on line 6
 Oracle Connect Error Error while trying to retrieve text for error ORA-12514

I suspect that the error is due to how I am giving the connection string


:Username is  bob
:Password is  man
:Server (of DB)  earth
:database name    planet

if ($c=ora_logon("bob@earth","man","planet")) {
echo "Successfully connected to Oracle.\n";
} else {
  echo "Oracle Connect Error " . ora_error();

Is this right ...please guide me in this so that I can atleast get teh connection string right .
Appreciate your time and effort
Hi :-)

ORA-12514: TNS:listener could not resolve SERVICE_NAME given in connect descriptor.
earth - in this case should have been a TNS server rather than a server.
You might  have a problem with the ORACLE_HOME variable.

You might want to replace ora_logon with ocilogon

$db = "(DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = db.ip.address)(PORT = db.port)) ) (CONNECT_DATA = (SID = YOUR_DB_SID) ) )";
$con = OCILogOn("user", "password",$db);

This, of course requires you to switch the functions you use to the new library.

Hope it helps...
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now