views:

85

answers:

1

I'm trying to set up a server for a project in my databases class. I'll be writing the project in php, deploying it via apache, and connecting to a remote oracle server. I'm having trouble with the oracle connection portion. I have the OCI8 module installed with oracle's instantclient version 10.2. I thought it was working because when I ran the following program from the console I got the right output.
Program:

<?php
$conn = oci_connect("asdf", "asdf", "asdf");
if (!$conn) {
   die("connection error\n");
}

$stid = oci_parse($conn, 'SELECT * FROM PARTS');
if (!$stid) {
   die("statement parsing error\n");
}

$r = oci_execute($stid);
if (!$r) {
   die("execution error\n");
}

print "<table border='1'\n";
while ($row = oci_fetch_array($stid, OCI_ASSOC+OCI_RETURN_NULLS)) {
   print "<tr>\n";
   foreach ($row as $item) {
      print "\t<td>" . ($item !== null ? htmlentities($item, ENT_QUOTES) : "&nbsp;") . "</td>\n";
   }
   print "</tr>\n";
}
print "</table>\n";

oci_free_statement($stid);
oci_close($conn);
?>

Result:
<table border='1'>
<tr>
<td>1</td>
<td>wrench</td>
<td>silver</td>
</tr>
<tr>
<td>2</td>
<td>hammer</td>
<td>brown</td>
</tr>
</table>

So I thought everything was fine. But when I visit the same php page in a browser I get the following error message:
Fatal error: Call to undefined function oci_connect() in /home/eric/apache2/htdocs/realestate/basicQuery.php on line 2
I thought that might mean that two different versions of php were getting used for the command line and in apache, so I ran phpinfo(); for both. But they both came back with the same php info (PHP Version 5.2.10-2ubuntu6.4). They are using different php.ini files (/etc/php5/apache2/php.ini and /etc/php5/cli/php.ini), but they both are exactly the same. I don't know where else to look for anything that might be different in one environment versus the other.
Thanks for any help!

A: 

PHP needs to know where to load its extension from (this bridges between PHP and the Oracle supplied libs). Since its working from the CLI you seem to have got the package installed.

If the ini files are the same, then you also need to check:

1) did you remember to restart apache after configuring the oracle libs?

2) does your webserver run as chroot?

3) what are the permissions on the oci8 extension? (i.e. is it readable by the webserver uid)

You also need to add the path to the oracle .so files to your ld.so.conf and run ldd or tweak your Env vars - but this will give a different error to the one you describe if you skip it.

HTH

C.

symcbean