Re: losing MySQL resource
| From: | Mailing Lists) | Date: | Mon, 09 Nov 2009 17:54:25 +0000 |
| Subject: | Re: losing MySQL resource | ||
| References: | 1 2 3 4 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-46635@lists.php.net to get a copy of this message | ||
Hi,
I got around this by creating a database wrapper class which gets passed the credentials from the app's config file. An instance of the class is created and saved in the session, and every query to the database runs through the class's Query() wrapper method which checks if the connection is alive and valid - if it isn't, it reconnects it before running the query.
Andy
On 9 November2009, at 16:46, Stan wrote:
How do I make an Object persistant for the duration of a Session? Thanks, "Chris" <dmagick@gmail.com> wrote in message news:4AB6B16C.8@gmail.com...Niel Archer wrote:($DBConnectI'm maintaining a session. I successfully connect to a databasevariable= mysql_connect()). I save the connection resource in a sessionqueries. It($_SESSION['connection'] = $DBConnect) ... to use in subsequent$_SESSION['$DBConnect']remains valid while the user is on the current page. print_r($_SESSION['connection']) yields 'Resource id #3', for instance. User browses to a new page ... in the same session.--PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.phpNo resources (whether they are persistent or not) can be stored in the session. http://www.php.net/manual/en/intro.session.php The big pink box has more info. --Postgresql & php tutorials http://www.designmagick.com/no longer references a valid mysql resource. print_r($_SESSION['connection']) yields '0'. Other "ordinary" values saved in $_SESSION variables remain valid. Is there something special about a mysql resource?Not about the resource itself, no. PHP closes connections to a Db when a script ends, unless the connection is persistent, so while the resource IS saved, the connection to which it refers no longer exists.