Solved

Oracle 10G XE + PHP connection using OCI8

Posted on 2011-03-25
1
1,397 Views
Last Modified: 2013-12-19
Hi Experts,

I recently configured Oracle 10G XE + PHP in by Ubuntu system. Everything went fine, but when i tried to connect it from PHP using oci8 the following error was occured:

Warning: oci_connect() [function.oci-connect]: OCIEnvNlsCreate() failed. There is something wrong with your system - please check that ORACLE_HOME and LD_LIBRARY_PATH are set and point to the right directories in /home/user2/workspace/test.php on line 5
Oracle Connect Error


Following is the code that we used for connection.


<?php
if ($c = oci_connect("username", "password", "localhost/XE")) {
   echo "Successfully connected to Oracle.";
   oci_close($c);
 } else {
   $err = oci_error();
   echo "Oracle Connect Error " . $err['text'];
 }
 ?>



Then we set the variables ORACLE_HOME and LD_LIBRARY_PATH in files ~/.bashrc, /.profile and apache2.conf one by one, but still the error was there. When we echoed $ORACLE_HOME from terminal, the correct path was shown. But $LD_LIBRARY_PATH was showing as null when we echoed it.

We solved this issue temporarly by setting these two variables directly in the php file just before the connection string as following.

putenv("ORACLE_HOME=/usr/lib/oracle/xe/app/oracle/product/10.2.0/server");
putenv("LD_LIBRARY_PATH=/usr/lib/oracle/xe/app/oracle/product/10.2.0/server/lib");



Can anyone suggest an alternate solution for this?
0
Comment
Question by:jacobbbc
1 Comment
 
LVL 40

Accepted Solution

by:
mrjoltcola earned 500 total points
ID: 35216317
Yes, you can tell Apache to pass env variables to your scripts. A specific example, using LD_LIBRARY_PATH is here in the Apache docs.

http://httpd.apache.org/docs/2.0/mod/mod_env.html
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
Shell script to create broker configuration file using current broker Configuration, solely for purpose of backup on Linux. Script may need to be modified depending on OS-installation. Please deploy and verify the script in a test environment.
This video shows information on the Oracle Data Dictionary, starting with the Oracle documentation, explaining the different types of Data Dictionary views available by group and permissions as well as giving examples on how to retrieve data from th…
This video explains what a user managed backup is and shows how to take one, providing a couple of simple example scripts.

680 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question