connect to a remote Oracle DB

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
yarons
Forum Newbie
Posts: 24
Joined: Mon Sep 11, 2006 7:25 am

connect to a remote Oracle DB

Post by yarons »

Hello,
I'm trying to connect to a remote Oracle server. I'm using PHP 5.1.6 and APACHE 2.2.3.
I have all the Oracle details I need, I have the server host, server name, user/pass and port.

How can I connect to it and start firing off queries?
I looked in some of the existing function (ora_logon,OCILogon, oci_connect) but it appears that none of them is accepting my connection details as parameters.

Thanks.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

The first note on oci_connect()'s page would suggest some form of DSN. On the older oracle pages, remote connections were added to some configuration file.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Does it require a server side client to connect? Does it require drivers?
User avatar
emmbec
Forum Contributor
Posts: 112
Joined: Thu Sep 21, 2006 12:19 pm
Location: Queretaro, Mexico

Post by emmbec »

Does anyone have an example on the connection string to a remote ORACLE database?? I've been trying to look for one, and an easy to follow tutorial but I just can't seem to find one. If anyone knows, could you please post it here? This are my DB details....

HOST: my.servername.com
PORT: 1234
SID: engr

Thanks!
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

http://www.connectionstrings.com/

There is an Oracle section in their. You might also want to search Oracle's web site as they are continually adding information about Oracle and PHP.
User avatar
emmbec
Forum Contributor
Posts: 112
Joined: Thu Sep 21, 2006 12:19 pm
Location: Queretaro, Mexico

Post by emmbec »

OK, after doing a lot of research I found that I had to do the following:

I had to uncomment the OCI8 extension in PHP.INI:

Code: Select all

extension=php_oci8.dll

I download the Instant Client Basic package for Windows from the Oracle site.

I created a subdirectory (e.g., c:\instantclient10_2) and copy these libraries from the zip file:
  • * oraociei10.dll
    * orannzsbb10.dll
    * oci.dll
I have edited the environment and add c:\instantclient10_2 to PATH before any other Oracle directories.

This is a sample from my PHP.INI file(I am using XAMPP so the location for this file is: C:\xampp\xampp\apache\bin I had a lot of problems editing the wrong PHP.INI file :wink:) for the extension path:

Code: Select all

; Directory in which the loadable extensions (modules) reside.
extension_dir = "C:\xampp\xampp\php\ext\"
Make sure it is correct and corresponds to where you have PHP installed.

NOTE: I am using XAMPP 1.5.5 and Windows 2000, there are instructions on the Oracle website to configure php and oracle on Linux.

I did all of that (which was in the oracle site http://www.oracle.com/technology/pub/no ... stant.html) and if you run PHPINFO() there HAS TO BE an OCI8 Section in that page if it is not, then you did something wrong.

Now here is an example of the connection string to oracle:

Code: Select all

$conn = OCILogon("USER_NAME", "PASSWORD","//oracle_server.domain:1521/DB_NAME");
Now the OCILogon instruction gets recognized, but I have just one more problem, my Oracle database is in another server, and when I run the above code I get the following warning:
Warning: ocilogon() [function.ocilogon]: ORA-12514: TNS:listener does not currently know of service requested in connect descriptor in C:\xampp\xampp\htdocs\test\test.php on line 2
Does anyone knows how to fix this???
Post Reply