Note that there are some explanatory texts on larger screens.

plurals
  1. POPHP to Oracle using oci8/MDB2 - _doConnect: unable to establish a connection
    primarykey
    data
    text
    <p>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.</p> <p>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.</p> <p>For some reason, in the new server, it doesn't work. It generates an error:</p> <blockquote> <p>_doConnect: [Error message: unable to establish a connection] ** oci8 (oci8)://gbsihr:xxx@localhost:1521/</p> <p>An error occurred while trying to connect to the database server. Error message: MDB2 Error: connect failed</p> </blockquote> <p>I truly have no idea what this means. This is my PHP connect function:</p> <pre><code>&lt;?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 '&lt;pre&gt;';var_dump($intSilent);print '&lt;/pre&gt;'; print '&lt;pre&gt;';var_dump($db_dsn);print '&lt;/pre&gt;'; print '&lt;pre&gt;';print $dbconnect-&gt;getDebugInfo();print '&lt;/pre&gt;'; echo "An error occurred while trying to connect to the database server.&lt;br&gt;\n"; echo "Error message: " . $dbconnect-&gt;getMessage() . "&lt;br&gt;\n"; echo "A more detailed error description: " . $dbconnect-&gt;getDebugInfo() . "&lt;br&gt;\n"; exit(); // Check whether the object is a connection or if($_SESSION["gENDebugInfo"] == "On"){ $_SESSION["gErrorNote"] = $dbconnect-&gt;getDebugInfo(); } if ($intSilent &lt; 0) { header("Location:" . $_SESSION["gENWebRoot"] . "showerror.php?ec=1003"); // Failed to connect exit(); } }else{ $dbconnect-&gt;setOption('portability', MDB2_PORTABILITY_ALL); } return $dbconnect; } ?&gt; </code></pre> <p>And this is the contents of configure.inc:</p> <pre><code>$_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'; </code></pre> <p>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.</p> <p>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).</p> <p>Here are my attempts to solve the problem:</p> <p>I tried copying the Basic Query Example from <a href="http://php.net/manual/en/oci8.examples.php" rel="nofollow noreferrer">this website</a>. 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:</p> <blockquote> <p>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</p> </blockquote> <p>I've also tried opening the httpd file in /etc/sysconfig/ and adding the following line to it:</p> <blockquote> <p>LD_LIBRARY_PATH="/u01/apps/oracle/product/11.2.0/xe/lib<br> export LD_LIBRARY_PATH</p> </blockquote> <p>And yet when I try to echo $LD_LIBRARY_PATH in the CLI, it won't return anything. It does appear in phpinfo(), though: <img src="https://i.stack.imgur.com/zHbIR.png" alt="enter image description here"><br> This is in contrast to $ORACLE_HOME, which I have to load manually every start-up by typing in <code>. /u01/app/oracle/product/11.2.0/xe/bin/oracle_env.sh</code> in the CLI, and does not appear under environments, but at least, can be echo'd. <img src="https://i.stack.imgur.com/2ZiKn.png" alt="enter image description here"></p> <p>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?</p> <p>I'm not much of a Linux-person, sorry. Any help on this would be much appreciated.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload