Re: Object instance and session

From: Date: Tue, 24 Jul 2007 11:19:11 +0000
Subject: Re: Object instance and session
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-259416@lists.php.net to get a copy of this message
Stefano Esposito wrote:
Hi all, i've a self-defined class describing an user. In the login page i create an instance of the user object and store it in $_SESSION['user']. When accessing $_SESSION['user'] from other pages (of course I do require('user.php'); and session_start();) i got this errors: Warning: mysqli::query() [function.mysqli-query]: Couldn't fetch mysqli in /home/httpd/html/uss_tyco3/user.php on line 390 Warning: user::get_unita_row() [function.user-get-unita-row]: Couldn't fetch mysqli in /home/httpd/html/uss_tyco3/user.php on line 391 Fatal error: Call to a member function fetch_assoc() on a non-object in /home/httpd/html/uss_tyco3/user.php on line 396
<snip code>
Any hint?
You are trying to store a resource (MySQLi connection) in the session. This is not possible. You need to implement __sleep and __wakeup methods in your class to properly close and re-create the connection on each request. See here for more: http://php.net/oop5.magic -Stut -- http://stut.net/

« previous php.general (#259416) next »