Page 1 of 1

Trouble with connecting to an Oracle database with PHP

PostPosted: 08. July 2009 19:59
by gskluzacek
I was getting the following error when trying to use php to connect to an oracle database

oci_connect() [function.oci-connect]: OCIEnvNlsCreate() failed. There is something wrong with your system - please check that PATH includes the directory with Oracle Instant Client libraries

Here's how I fixed it....

I had just installed XAMPP on Win XP and wanted to use PHP to connect to an Oracle database. I had not previously installed XAMPP or anything Oracle on the computer - here's how I got OCI8 working...

I downloaded and ran the XAMPP installer & installed to the C:\xampp directory

http://www.apachefriends.org/download.p ... taller.exe

I edited the c:\xampp\php\php.ini and uncommented the following line (by taking out the ';' at the beginning of the line)

;extension=php_oci8.dll

next I downloaded the Oracle 10 instant client (user login required)

http://download.oracle.com/otn/nt/insta ... .2.0.4.zip

unzipped and copied the files into the C:\xampp\apache\bin directory

Finally I restarted Apache... I can now connect to an oracle db using the following:

Code: Select all
$uid = '<uid>';
$pw = '<pw>';
$conn = '//<host>:<port>/<sid>';

$ora_dbh = oci_connect($uid, $pw, $conn);
if (!$ora_dbh) {
   $e = oci_error();
   die ("Could not connect to Oracle " . $e['message']);
}

Here's example connection string

//mydbhost.example.com:1521/PRODDB


hopes this helps someone as it took me much searching and lots of trial and error.

Regards,
Greg Skluzacek