Solved

Oracle 10G XE + PHP connection using OCI8

Posted on 2011-03-25
1
1,415 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

Introduction A previously published article on Experts Exchange ("Joins in Oracle", http://www.experts-exchange.com/Database/Oracle/A_8249-Joins-in-Oracle.html) makes a statement about "Oracle proprietary" joins and mixes the join syntax with gen…
Background In several of the companies I have worked for, I noticed that corporate reporting is off loaded from the production database and done mainly on a clone database which needs to be kept up to date daily by various means, be it a logical…
This video shows how to Export data from an Oracle database using the Datapump Export Utility.  The corresponding Datapump Import utility is also discussed and demonstrated.
This video shows how to copy an entire tablespace from one database to another database using Transportable Tablespace functionality.
Suggested Courses

627 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