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
Saving a database connection to a session variable
Moderator: General Moderators
How do you mean by storing database connections... Do you mean like this?
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();
Code: Select all
<?php
$connection = mysql_connect("locahost","user","password");
$_SESSIONї'connection'] = $connection;
?>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
take a look at The magic functions __sleep and __wakeup as example as how to restore ressources like db-connections