Page 1 of 1

Connecting to Oracle with PHP

Posted: Mon Apr 20, 2009 6:45 pm
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

Re: Connecting to Oracle with PHP

Posted: Tue Apr 21, 2009 7:33 am
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.

Re: Connecting to Oracle with PHP

Posted: Tue Apr 21, 2009 10:51 am
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>';
}