Solved

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

Posted on 2004-08-23
3
2,120 Views
Last Modified: 2013-12-12
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

url=jdbc:oracle:thin:@server:1521:db

And from The Oracle client(Toad) I connect by using the  
username@server.db

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

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

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

Ora_Commit ($connection);
Ora_Close ($cursor);
Ora_Logoff ($connection);
?>
*****************************************************************************************************

Thanks for your time
0
Comment
Question by:micro_learner
3 Comments
 
LVL 26

Expert Comment

by:ushastry
Comment Utility
0
 

Author Comment

by:micro_learner
Comment Utility
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

say

: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";
  ora_commitoff($c);
  ora_logoff($c);
} 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
0
 
LVL 9

Accepted Solution

by:
e-tsik earned 500 total points
Comment Utility
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
http://il2.php.net/manual/en/ref.oci8.php

$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...
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now