Page 1 of 1

Saving a database connection to a session variable

Posted: Tue Oct 01, 2002 9:46 am
by tfneves
Hi All!

I have a problem. I can save strings, integers to session variables and retrieve them from page to page. But when it comes to a database connection I cannot save it. Does anybody have a solution to this?

Also, what is the most secure method for using session vars?

Thanks,
Tony

Posted: Tue Oct 01, 2002 9:50 am
by Takuma
How do you mean by storing database connections... Do you mean like this?

Code: Select all

<?php
$connection = mysql_connect("locahost","user","password");
$_SESSIONї'connection'] = $connection;
?>
If you're doing this it's not going to work because $connection hasn't got a connection it's just got the results of connection. If you want to keep the connection open use mysql_pconnet();

Posted: Tue Oct 01, 2002 9:51 am
by volka
you cannot save ressources to sessions.
take a look at The magic functions __sleep and __wakeup as example as how to restore ressources like db-connections