Reputation: 4386
I'm running a Linux Fedora 19 setup with Oracle 11g, PHP 5.5.4, Apache 2.4.6, and PEAR 1.9.4. In addition to this, I have the OCI8 plug-in for PHP downloaded and enabled, and have downloaded MDB2 and the MDB2_Driver_oci8.
The goal is to connect my webpage to the Oracle 11g database. This already works in an existing setup (which I didn't do), and I'm trying to replicate it in a new setup.
For some reason, in the new server, it doesn't work. It generates an error:
_doConnect: [Error message: unable to establish a connection] ** oci8 (oci8)://gbsihr:xxx@localhost:1521/
An error occurred while trying to connect to the database server. Error message: MDB2 Error: connect failed
I truly have no idea what this means. This is my PHP connect function:
<?php
include_once('includes/configure.inc');
require_once 'MDB2.php';
function DB_connect($intSilent = -1){
$db_dsn = $_SESSION['DB_Type'] ."://";
$db_dsn .= $_SESSION['DB_Username'] .":";
$db_dsn .= $_SESSION['DB_UserPassword'] ."@";
$db_dsn .= $_SESSION['DB_Host'] .":";
$db_dsn .= $_SESSION['DBPort'] ."/?service=";
$db_dsn .= $_SESSION['DB_DbName'];
if (PEAR::isError($dbconnect)) {
print '<pre>';var_dump($intSilent);print '</pre>';
print '<pre>';var_dump($db_dsn);print '</pre>';
print '<pre>';print $dbconnect->getDebugInfo();print '</pre>';
echo "An error occurred while trying to connect to the database server.<br>\n";
echo "Error message: " . $dbconnect->getMessage() . "<br>\n";
echo "A more detailed error description: " . $dbconnect->getDebugInfo() . "<br>\n";
exit();
// Check whether the object is a connection or
if($_SESSION["gENDebugInfo"] == "On"){
$_SESSION["gErrorNote"] = $dbconnect->getDebugInfo();
}
if ($intSilent < 0) {
header("Location:" . $_SESSION["gENWebRoot"] . "showerror.php?ec=1003"); // Failed to connect
exit();
}
}else{
$dbconnect->setOption('portability', MDB2_PORTABILITY_ALL);
}
return $dbconnect;
}
?>
And this is the contents of configure.inc:
$_SESSION["gENWebRoot"] = '/hrweb/';
$_SESSION['DB_Type'] = 'oci8';
$_SESSION['DB_Host'] = 'localhost';
$_SESSION['DB_Username'] = 'gbsihr';
$_SESSION['DB_UserPassword'] = 'ids21';
$_SESSION["DBPort"] = '1521';
$_SESSION['DB_DbName'] = 'xe';
As this works on another setup, I'm not sure where the error lies. OCI8 seems to be in order, though I did go through hoops to get it working.
I did do some research, with only two vague results - one pointing to the oci8.php itself, and the other, an Oracle TNS error (unlikely, given the lack of errors).
Here are my attempts to solve the problem:
I tried copying the Basic Query Example from this website. I modified the "hr" and "welcome", and ran it on my new setup (it works fine on the older one). And this is the result:
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. Error while trying to retrieve text for error ORA01804
I've also tried opening the httpd file in /etc/sysconfig/ and adding the following line to it:
LD_LIBRARY_PATH="/u01/apps/oracle/product/11.2.0/xe/lib
export LD_LIBRARY_PATH
And yet when I try to echo $LD_LIBRARY_PATH in the CLI, it won't return anything. It does appear in phpinfo(), though:
This is in contrast to $ORACLE_HOME, which I have to load manually every start-up by typing in . /u01/app/oracle/product/11.2.0/xe/bin/oracle_env.sh
in the CLI, and does not appear under environments, but at least, can be echo'd.
There are a lot of variables in the old setup under environment; LD_LIBRARY_PATH, ORACLE_HOME, and ORACLE_SID being the most noteworthy. I only see LD_LIBRARY_PATH in the envvars file, though. Should I add them as well to the httpd file?
I'm not much of a Linux-person, sorry. Any help on this would be much appreciated.
Upvotes: 0
Views: 2371
Reputation: 88
Just add this line
$dbconnect = DB::connect($db_dsn);
to function DB_connect
like this
...
$dbconnect = DB::connect($db_dsn);
if (PEAR::isError($dbconnect)) { ...
Upvotes: 0
Reputation: 3864
Can you connect to oracle outside of php? I presume you have a valid tns.ora file set up.
I needed these two lines set in my VirtualHost definition, note TNS_ADMIN is defined also, perhaps you do too:
SetEnv ORACLE_HOME /opt/oracle/instantclient
SetEnv TNS_ADMIN /usr/lib/oracle/11.2/client/network/admin/network/admin**
Upvotes: 0
Reputation: 31146
I suggest you try to connect to your oracle database by using the plain oci8 functions and the same login parameters as you use for MDB2.
My guess is that this will fail as well, but might give you more error details.
Upvotes: 1