Connecting to Oracle with PHP

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
FyreHeart
Forum Newbie
Posts: 5
Joined: Tue Feb 17, 2009 12:27 am

Connecting to Oracle with PHP

Post by FyreHeart »

I'm trying to connect to an Oracle 10g database through PHP to run some web reports. The server admin has installed Oracle (instant client, it looks like) and enabled OCI8 support in PHP. He says he can connect to the Oracle server through the Oracle client now installed on the web server. He also set up a TNSNAMES.ORA file for me when I ran into my initial connection problems.

I've tried connecting with both Instant Connect syntax and TNSNAMES.ORA syntax to no avail. These are the strings I've used with oci_connect (database names have been changed to protect the innocent):

Code: Select all

$oracleServer = '//txsl.vwt.mynet.com:1521/db';
$tnsNames = 'db'
$urlServer = 'txsl.vwt.mynet.com/db';
$ipServer = '10.0.0.16/db';
Help? :banghead:

Thanks in advance.

-John
Last edited by FyreHeart on Tue Apr 21, 2009 4:10 pm, edited 1 time in total.
ghogilee
Forum Newbie
Posts: 19
Joined: Tue Apr 07, 2009 8:45 am
Location: Novi Sad, Serbia

Re: Connecting to Oracle with PHP

Post by ghogilee »

If I understand you well, you r asking for this? (ofcourse with OCI extension):

Code: Select all

 
<?php
 if ($c = oci_connect("blah", "blah_password", "localhost/base")) {
   echo "Successfully connected to Oracle.n";
   oci_close($c);
 } else {
   $err = oci_error();
   echo "Oracle Connect Error";
 }
 ?>
 
And one more thing. You might need to set Oracle environment variables such as ORACLE_HOME, etc prior to starting your web server.
FyreHeart
Forum Newbie
Posts: 5
Joined: Tue Feb 17, 2009 12:27 am

Re: Connecting to Oracle with PHP

Post by FyreHeart »

Thanks very much for the quick response.

It looks like you're using my "urlserver" approach. Referencing the variables above, here's what I've attempted. From what you're telling me above, my syntax is fine and it's still a server problem?

Code: Select all

$dbConnection = oci_connect($oracleUser, $oraclePassword, $oracleServer);
if(!$dbConnection) {
    $error = oci_error(); 
    echo '<p style="color: red; font-weight: bold;">Error connecting to Oracle via Easy Connect: '.$error['message'].'</p>';
}
 
$dbConnection = oci_connect($oracleUser, $oraclePassword, $tnsNames);
if(!$dbConnection) {
    $error = oci_error(); 
    echo '<p style="color: red; font-weight: bold;">Error connecting to Oracle via TNSNAMES.ORA: '.$error['message'].'</p>';
}
 
$dbConnection = oci_connect($oracleUser, $oraclePassword, $urlServer);
if(!$dbConnection) {
    $error = oci_error();
    echo '<p style="color: red; font-weight: bold;">Error connecting to Oracle via URL: '.$error['message'].'</p>';
}
 
$dbConnection = oci_connect($oracleUser, $oraclePassword, $ipServer);
if(!$dbConnection) {
    $error = oci_error();
    echo '<p style="color: red; font-weight: bold;">Error connecting to Oracle via IP: '.$error['message'].'</p>';
}
Post Reply