I have an Oracle backed website. To avoid doing repeated db connections, I'm trying to put the database commands as functions in an include file and return the connection resource to the main pages for display. The resource is not getting returned.
test-include.php:
define('DB_USER', 'scott');
define('DB_PASS', 'tiger');
define('DB_NAME', 'mydb');
$conn = OCILogon(DB_USER, DB_PASS, DB_NAME);
function db_query($conn,$query)
{
$stmt = OCIParse($conn,$query);
OCIExecute($stmt);
return $stmt;
}
A main page:
<?php
include "./test-include.php";
$query = "select item_id, short_desc from products order by item_id";
db_query($conn,$query);
while (OCIFetchInto($stmt,$row))
{
$id = $row[0];
$desc = $row[1];
echo $id;
echo $desc;
}
?>
This returns the error
Supplied argument is not a valid OCI8-Statement resource
at the 'while...' line, which I'm guessing means that there's no value for $stmt.
Any ideas?
Thanks,
Sheila