PLEASE detailed __sleep() and __wakeup() code for databaseconnection

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • esimons
    New Member
    • Oct 2006
    • 1

    PLEASE detailed __sleep() and __wakeup() code for databaseconnection

    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.
  • ronverdonk
    Recognized Expert Specialist
    • Jul 2006
    • 4259

    #2
    Reading your request, I bet you haven't looked in the standard PHP documentation at php.net. The following link gives quite some tips and samples on using the serialize(), unserialize(), __sleep() and __wakepup functions. See The magic functions __sleep and __wakeup

    Ronald :cool:

    Comment

    Working...