[nycphp-talk] Passing Objects Via Session in PHP 4
Dan Cech
dcech at phpwerx.net
Mon Sep 27 14:59:20 EDT 2004
Joseph Crawford wrote:
> the sessions seem to carry over now however my resource ID for my
> $db->connection keep changing, i have even altered the open method to
> look like this
>
> if(!$this->connection) {
> $conn = mysql_connect($hostname, $username, $password);
> if(!$conn) trigger_error(mysql_error(), E_USER_ERROR);
> else $this->connection = $conn;
> }
>
> any ideas how to keep that from getting a new resource handle but
> rather use the same one?
Ok,
1. You don't need to manually serialize stuff you put into the session
through $_SESSION, php automatically serializes and unserializes the
$_SESSION array for you.
2. You cannot store a resource ID in a session. The resource ID is
specific to that particular instance of the script, you will have to
reopen the database connection for each request.
If you use persistent database connections it *may* still use the same
connection to the database, but the resource ID will be different.
Dan
More information about the talk
mailing list