I need to save the value of mysql_connect() in a global variable that's accessible in every php file in my project
for example, $db_ServerVal = mysql_connect()
.
I need to be able to call mysql_connect only once, at the start of the program.
Then in every php file -- that $db_ServerVal
MUST be valid. Not the first time.
EVERY time. Until I call mysql_close( $db_ServerVal)
;
Can I use $GLOBALS[]
, the pre-defined array in php, to store my $db_ServerVal
database connection?
The other problem is -- I need have a 'close' event when the browser window closes,
so that I will know that it's time to call mysql_close( $db_ServerVal);
.
I can't call mysql_close()
at the end of my index.php file since that will close the
database prematurely, then every time I access the database I'd have to mysql_connect()
again.
While I could call mysql_connect()
and mysql_close()
before and after each database call -- I'm not
sure if that's the standard way things are done.