Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Oracle 10G XE + PHP connection using OCI8

Posted on 2011-03-25
1
Medium Priority
?
1,471 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 2000 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

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

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

This post first appeared at Oracleinaction  (http://oracleinaction.com/undo-and-redo-in-oracle/)by Anju Garg (Myself). I  will demonstrate that undo for DML’s is stored both in undo tablespace and online redo logs. Then, we will analyze the reaso…
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.
Via a live example, show how to take different types of Oracle backups using RMAN.
This video shows how to recover a database from a user managed backup
Suggested Courses

877 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