PHP DB connection objects
If you create an instance of a database connection object containing a 'mysql_connect' command globally, then declare a local reference to the object within a function, ie:
<?
include("DBClass.php");
// connection instance
$dbObj = new DBInit();
function foo ()
{
$dbObj = $GLOBALS["dbObj"];
// will the local 'copy or reference' connection above also be closed?
$GLOBALS["dbObj"]->closeConnection();
}
?>
...will all connections close (assuming there is a closeConnection method) with the last line inside the function? PHP(4) copies alot by value and not reference and I don't want to leave connections open.
Thanks,
TM
Mark Hensler posted this at 08:11 — 27th March 2004.
He has: 4,048 posts
Joined: Aug 2000
I believe everything will be closed. The reason for this is that your closing a handle (the value in the variable) and not unseting the variable itself.
If you have time, try it and let us know.
Mark Hensler
If there is no answer on Google, then there is no question.
TonyMontana posted this at 02:07 — 28th March 2004.
They have: 218 posts
Joined: Apr 2001
Yep, no connections were left open.
Thanks,
TM
Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.