Question

I have been attempting to connect to an Oracle DB with PHP for some time now with no success. All the guides I have been looking at mention two methods. One is to compile PHP with the oci8 support, which I can't figure out how to do since I installed PHP using yum. The other method is to use the ODBC connection but that also is not working correctly.

The server that I am using for this is an Oracle Enterprise Linux box. I have installed PHP and Apache using yum. I installed php-odbc through yum as well. I have installed the Oracle Client using the Oracle Universal Installer, setup the tnsnames.ora file and tnsping works to the database.

I have been using these as guides for oci8: http://www.oracle.com/webfolder/technetwork/tutorials/obe/db/oow10/php_db/php_db.htm http://php.net/manual/en/oci8.installation.php

Using PHP 5.3.3 and installed the full client for Oracle 11gR2.

Here is the particular code that I have attempted.

<?php
$connect = oci_connect("username","password","//databaseserver:1521/SID");
if (!$connect){
        $m = oci_error();
        echo $m['message'], "\n";
        exit;
}
else {
        print "Connected to Oracle!";
}
//Close the connection
oci_close($connect);
?>

The error that I am getting when I do a php -F is that it doesn't recognize the command 'oci_connect'. Hence my initial questioning about how to add this support after installing PHP. Things I've been reading have stated that it is included above 5.3. but that is obviously not the case.

Was it helpful?

Solution

Figured this out after much research. If PHP is installed with yum, you can't recompile it but instead must install the individual modules. I was missing several modules that were not indicated by Oracle. This was the installed packages that I finally got this to work with.

php.x86_64
php-cli.x86_64
php-common.x86_64
php-devel.x86_64
php-pdo.x86_64
php-pear.noarch
php-pecl-apc.x86_64

After installing these packages through yum and following the steps in this guide, I was able to get this successfully done.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top