473,395 Members | 1,437 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

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 databaseconnection 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.
Oct 25 '06 #1
1 1926
ronverdonk
4,258 Expert 4TB
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:
Oct 25 '06 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Rob Long | last post by:
Hey I'm building a webapp with tons of objects all over the place, a lot of which are quite complex, meaning they could have many subclasses and many nested object members. I'm implementing a...
0
by: Jack | last post by:
Hi, I have the following problem. I have a main data entry form which has a link to a detailed data entry form. The value of the link in the main form is the sum total of all the line items...
8
by: phil goddard | last post by:
This homework tests your understanding of pointers and how to use pointers with arrays and functions. What we want to do is find the next highest int in an array based on a given float, i.e. in...
7
by: Newbie! | last post by:
Hi Group, I have a project which has a access database with it. I`ve added the Database Adapter And Database connected to each of my forms, generated a Dataset, and added the relivant table from...
0
by: ECathell | last post by:
In Theory is this the correct use of a singleton object? I only want them to be able to run this process once(of course by closeing and restarting the application stops that functionality). Is this...
1
by: David Van D | last post by:
Hi there, A few weeks until I begin my journey towards a degree in Computer Science at Canterbury University in New Zealand, Anyway the course tutors are going to be teaching us JAVA wth bluej...
1
PEB
by: PEB | last post by:
POSTING GUIDELINES Please follow these guidelines when posting questions Post your question in a relevant forum Do NOT PM questions to individual experts - This is not fair on them and...
1
by: =?Utf-8?B?c2NvdHRybQ==?= | last post by:
I have some code to read the contents of a varbinary(max) field in SQL Server 2005. It is working ok I just wanted to know if anyone had any comments on it's efficiency. Code to read from the...
4
by: jonc1 | last post by:
Can anyone explain how these work in relation to setting and application setting files. I know that application settings can not be modified programatically at runtime, although they can be changed...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.