|
Posted by J.O. Aho on 03/21/06 17:30
kees hessels wrote:
> Hi there, How (if) can i store the link from a mysql connect in a session
> variable
> something like
> $_SESSION['db_link']=mysql_connect ( $server, $username, $password );
>
> Currently de mysql link is not saved in the session ...while ather vars are
> properly stored and retrieved ????
> The goal of the exercise is to limit the amount of mysql_connect in my app.
You don't, there aren't any good effects of saving the resource in a session.
mysql_connect() results in a disconnect from the sql server when the
php-script has been run.
mysql_pconnect() tries to keep the connection alive, but still do not save the
resource to a session, as you never know if the connection will stay alive to
the next php-script, so you need to rerun the mysql_pconnect(), it will check
if the connection is still alive, is so it won't do anything else, but if it
would be so it's dead, then it will reconnect to the sql-server.
http://www.php.net/manual/en/function.mysql-pconnect.php
You will have as many mysql_pconnect() in your code as you did have
mysql_connect(), but you will have less overhead.
//Aho
[Back to original message]
|