English 中文(简体)
OCI8 functions not found when run by apache with php5
原标题:

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
");
}

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

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

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

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!

问题回答

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.

Did you have the oci8 extension installed in your system? Check that if it is not then to install it follow the below links?

For understanding refer this. Installing oci8 extension in linux for php?

For clear instruction to install refer this link. http://www.oracle.com/technetwork/articles/dsl/technote-php-instant-12c-2088811.html

Check your php.ini file whether you have the following things set.

extension=oci.so

extension_dir="Your path where .so files are present"

After the installation you should restart apache. Let me know if this helps you.

This can be a lot of stuff, the OCI8 module isn t installed properly, isn t loaded by apache or even a dependency isn t installed.

Installing OCI8

The easiest way to install OCI8 is using pecl:

pecl install oci8-2.0.12 # for PHP 5.5/6

Enabling module

Then you need to load it by placing the extension=oci8.so in your php.ini.

Now make sure that there is a oci8.so file in your extension_dir configuration. This can be found in phpinfo or executing php -i | grep extension_dir. For example, mine is /usr/lib/php/20131226.

Restart your apache executing apachectl restart and see if there is a oci8 configuration in your phpinfo.

The mercy shot

If you tried everything and it didn t work (that already happened to me), make sure libaio1 is installed in your system. If it isn t, install it by executing apt install libaio1 and restart your apache. In my case, it did the trick. Hope that helps.





相关问题
Export tables from SQL Server to be imported to Oracle 10g

I m trying to export some tables from SQL Server 2005 and then create those tables and populate them in Oracle. I have about 10 tables, varying from 4 columns up to 25. I m not using any constraints/...

Connecting to Oracle 10g with ODBC from Excel VBA

The following code works. the connection opens fine but recordset.recordCount always returns -1 when there is data in the table. ANd If I try to call any methods/properties on recordset it crashes ...

How to make a one to one left outer join?

I was wondering, is there a way to make a kind of one to one left outer join: I need a join that matches say table A with table B, for each record on table A it must search for its pair on table B, ...

Insert if not exists Oracle

I need to be able to run an Oracle query which goes to insert a number of rows, but it also checks to see if a primary key exists and if it does, then it skips that insert. Something like: INSERT ALL ...

How can I store NULLs in NOT NULL field?

I just came across NULL values in NOT-NULL fields in our test database. How could they get there? I know that NOT-NULL constraints can be altered with NOVALIDATE clause, but that would change table s ...

Type reference scope

I m studying databases and am currently working on a object-relational DB project and I ve encountered a small problem with the number of possible constraints in an object table. I m using "Database ...

OracleParameter and DBNull.Value

we have a table in an Oracle Database which contains a column with the type Char(3 Byte). Now we use a parameterized sql to select some rows with a DBNull.Value and it doesn t work: OracleCommand ...

热门标签