Solved

Oracle 10G XE + PHP connection using OCI8

Posted on 2011-03-25
1
1,385 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

Why are Office 365 signatures so complicated?

Trying to setup transport rules for Office 365 email signatures and can’t quite figure it out? Having to test the signature over and over? Make things simple by using Exclaimer Cloud - Signatures for Office 365.

Question has a verified solution.

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

Preface There are many applications where some computing systems need have their system clocks running synchronized within a small margin and eventually need to be in sync with the global time. There are different solutions for this, i.e. the W3…
If, like me, you have a lot of Dell servers in the estate you manage this article should save you a little time. When attempting to login to iDrac on any server I would be presented with two errors. The first reads "Do you want to run this applicati…
This video explains at a high level with the mandatory Oracle Memory processes are as well as touching on some of the more common optional ones.
This video explains at a high level about the four available data types in Oracle and how dates can be manipulated by the user to get data into and out of the database.

947 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now