1 Reply Latest reply on Dec 26, 2012 6:32 AM by cj

    How to share connection


      Happy Holidays!

      How can I share connection among different PHP files.

      for e,g,

      Content of first files db.php

      $db_host = "localhost/XE";
      $db_user = "my_user";
      $db_pass = "1234";

      content of second file.

      include_once 'db.php';
      $connect = oci_connect ($db_user, $db_pass, $db_host) or die ("Couldn't connect!");

      content of third file


      include ('../includes/connect.php');

      $stid = oci_parse($conn, 'SELECT * FROM emp');

      echo "<table border='1'>\n";
      while ($row = oci_fetch_array($stid, OCI_ASSOC+OCI_RETURN_NULLS)) {
      echo "<tr>\n";
      foreach ($row as $item) {
      echo " <td>" . ($item !== null ? htmlentities($item, ENT_QUOTES) : " ") . "</td>\n";
      echo "</tr>\n";
      echo "</table>\n";

      My question is How I pass connection variable among PHP file? for e.g. the variable $conn in above example.

      My above example of third file will not work until I add following line
      $conn = oci_connect ($db_user, $db_pass, $db_host);

      Where in MySQL its not required.

      Adding oci_connect is safe?

      Thank you
        • 1. Re: How to share connection
          Use a debugger such as NetBeans and check your code. You might notice that one file uses $connect and the other uses $conn.

          Free PHP Oracle book: http://www.oracle.com/technetwork/topics/php/underground-php-oracle-manual-098250.html