Possible Duplicate:
Do I really need to do mysql_close()
Maybe the first question to ask is, do I even need to close my MySQL connections? Is this something that is done automatically at the end of each script?
Anyway, in the example below, you can see if you call DoOtherStuff() from DoStuff(), your database connection is closed before you can run the MySQL query right after the call to DoOtherStuff(). Now, what is the rule for opening and closing MySQL connections? Can I just not close any connections and open a connection whenever a function requires it? Will this create more than necessary database connections and make my code slower? Any tips for this? I'm just doing what feels best, I feel a little lost.
function DoStuff(){
$connection = mysql_connect(...);
DoOtherStuff();
mysql_query(...);//This won't run
mysql_close($connection);
}
function DoOtherStuff(){
$connection = mysql_connect(...);
//Does other stuff
mysql_close($connection);
}