Package home | Report new bug | New search | Development Roadmap Status: Open | Feedback | All | Closed Since Version 1.12.2

Request #928 __wakeup() for serialize & unserialize
Submitted: 2004-03-01 12:51 UTC
From: koma at pp dot inet dot fi Assigned: danielc
Status: Closed Package: DB
PHP Version: 4.3.2 OS: Linux
Roadmaps: (Not assigned)    
Subscription  


 [2004-03-01 12:51 UTC] koma at pp dot inet dot fi
Description: ------------ If I try to keep the db-object trough the session and I serialize it in the code after I come back and unserialize the object it doesn't work anymore. Suggestion: using __wakeup to reinitialize to the same dsn if it is made with php something similar if made with something else. Go-around: create class that extends DB.php and it has __wakeup() { $this->db = DB::connect($this->_dsn); } Reproduce code: --------------- <?php require_once('DB.php'); session_start(); $db = DB::connect("mysql://VPP:VPP@localhost/VPP"); $_SESSION['db'] = serialize($db); $db2 = unserialize($_SESSION['db']); if(DB::IsError($db2)) echo "Virhe"; if(is_object($db2)) echo "Is a obect"; else echo not a object"; $query = "SELECT * FROM Players"; $rows = $db->getAll($query); print_r($rows); $rows = $db2->getAll($query); print_r($rows); ?> Expected result: ---------------- the db2 object should return what db-object returned Actual result: -------------- Is a objectArray ( [0] => Array ( [0] => 5 [1] => Koma [2] => 9627df7a4a5b849f67fce863e82adc71 [3] => 1 ) [1] => Array ( [0] => 2 [1] => Testi [2] => 521c62729138ccf4f618d72a55623658 [3] => 1 ) ) DB_Error Object ( [error_message_prefix] => [mode] => 1 [level] => 1024 [code] => -14 [message] => DB Error: no database selected [userinfo] => SELECT * FROM Players [nativecode=**] [backtrace] => Array ( [0] => Array ( [file] => /usr/local/lib/php/DB.php [line] => 739 [function] => PEAR_Error [class] => DB_Error [type] => -> ) [1] => Array ( [file] => /usr/local/lib/php/PEAR.php [line] => 532 [function] => DB_Error [class] => DB_Error [type] => -> ) [2] => Array ( [file] => /usr/local/lib/php/DB/common.php [line] => 495 [function] => raiseError [class] => DB_mysql [type] => -> ) [3] => Array ( [file] => /usr/local/lib/php/DB/mysql.php [line] => 770 [function] => raiseError [class] => DB_mysql [type] => -> ) [4] => Array ( [file] => /usr/local/lib/php/DB/mysql.php [line] => 218 [function] => mysqlRaiseError [class] => DB_mysql [type] => -> ) [5] => Array ( [file] => /usr/local/lib/php/DB/common.php [line] => 1135 [function] => simpleQuery [class] => DB_mysql [type] => -> ) [6] => Array ( [file] => /usr/local/lib/php/DB/common.php [line] => 1572 [function] => query [class] => DB_mysql [type] => -> ) [7] => Array ( [file] => /var/www/html/php5/testi.php [line] => 16 [function] => getAll [class] => DB_mysql [type] => -> ) ) [callback] => )

Comments

 [2004-03-12 03:06 UTC] danielc
Changing summary.
 [2005-02-03 00:35 UTC] danielc
Added in CVS.