Skip to Main Content

How to share connection

24954Dec 25 2012 — edited Dec 26 2012

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) : "&nbsp;") . "</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
Post Details
Added on Dec 25 2012
1 comment