Solved

Oracle 10G XE + PHP connection using OCI8

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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Configuring and using Oracle Database Gateway for ODBC Introduction First, a brief summary of what a Database Gateway is.  A Gateway is a set of driver agents and configurations that allow an Oracle database to communicate with other platforms…
How to Unravel a Tricky Query Introduction If you browse through the Oracle zones or any of the other database-related zones you'll come across some complicated solutions and sometimes you'll just have to wonder how anyone came up with them.  …
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.
This video shows how to copy an entire tablespace from one database to another database using Transportable Tablespace functionality.

760 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

21 Experts available now in Live!

Get 1:1 Help Now