I am searching for days now to get a concrete example of how to use the __sleep() and __wakeup() function in a class to restore a databaseconnect ion when passing an object from one page to another by putting it in a session-variable.
What I already know is that you should load the class before the session_start() function etc... What I DO NOT know is how the concrete code in the __sleep() and __wakeup() functions should be in order to automatically restore the database connection.
In my class I have the following database connection code in the class constructor:
$this->db = mysql_connect($ db_info[host], $db_info[username], $db_info[password])
or die ("Error connection MySQL");
mysql_select_db ($db_info[dbname], $this->db)
or die ("Database cannot be opened");
What code do I put in the __sleep() and __wakeup() functions to restore that database connection. So please fill in:
function __sleep()
{
............... .
}
function __wakeup()
{
...............
}
The only information I find on the web, in the PHP manuals and books I have is simply: "you can use the magick functions __sleep() and __wakeup() to restore a database connection when serializing an object". NO further explanation.
I am getting a bit desperate here.
What I already know is that you should load the class before the session_start() function etc... What I DO NOT know is how the concrete code in the __sleep() and __wakeup() functions should be in order to automatically restore the database connection.
In my class I have the following database connection code in the class constructor:
$this->db = mysql_connect($ db_info[host], $db_info[username], $db_info[password])
or die ("Error connection MySQL");
mysql_select_db ($db_info[dbname], $this->db)
or die ("Database cannot be opened");
What code do I put in the __sleep() and __wakeup() functions to restore that database connection. So please fill in:
function __sleep()
{
............... .
}
function __wakeup()
{
...............
}
The only information I find on the web, in the PHP manuals and books I have is simply: "you can use the magick functions __sleep() and __wakeup() to restore a database connection when serializing an object". NO further explanation.
I am getting a bit desperate here.
Comment