I'm relatively new to PHP/MySQL and I've heard about maintaining a
persistent connection to the database. To save overhead, I'd like to
maintain the connection in a session variable, but I have a few
questions first.
I'm able to establish session variables and test them with isset() to
avoid re-defining them with each new web-page load. So is this really
as simple as
if (!isset($_SESSI ON['connection'])) {
$connection = mysql_connect(" SomeServer","Us erName","passwo rd");
$_SESSION['connection'] = $connection;
};
Will this work? and is there a better way to do it--or a more
conventional way? What should I be thinking about vis a vis security
regarding this connection.
Is there a recommended way to make the session's connection variable
"expire"? I suppose I could store the time the connection was
established and then check the elapsed time with each web-page
re-load, dumping the session if it's been too long.
Is there a preferred way to store $connection without using
$_SESSION[]?
Thanks,
M. Katz
persistent connection to the database. To save overhead, I'd like to
maintain the connection in a session variable, but I have a few
questions first.
I'm able to establish session variables and test them with isset() to
avoid re-defining them with each new web-page load. So is this really
as simple as
if (!isset($_SESSI ON['connection'])) {
$connection = mysql_connect(" SomeServer","Us erName","passwo rd");
$_SESSION['connection'] = $connection;
};
Will this work? and is there a better way to do it--or a more
conventional way? What should I be thinking about vis a vis security
regarding this connection.
Is there a recommended way to make the session's connection variable
"expire"? I suppose I could store the time the connection was
established and then check the elapsed time with each web-page
re-load, dumping the session if it's been too long.
Is there a preferred way to store $connection without using
$_SESSION[]?
Thanks,
M. Katz
Comment