473,765 Members | 1,994 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

PLEASE detailed __sleep() and __wakeup() code for databaseconnect ion

1 New Member
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.
Oct 25 '06 #1
1 1945
ronverdonk
4,258 Recognized Expert Specialist
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
1482
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 memory caching mechanism to store these objects between requests and share them between different user sessions. In order for my memory caching mechanism to work, objects must be serialised before they are placed into the cache. In PHP5, this
0
1325
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 in the detailed form. The detailed form has fields to capture the individual line items like contracted service expense, travel expense etc. I am capturing the total of individual line items using session variables so
8
1337
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 the following example, based on the float 7.11 we want to find the 8. Tasks: 1) Include all the required libraries and define a main(). 2) In main, define a a. float called myFloat, initialize it with 7.11
7
1007
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 the Database into it. Is this right or should i only add my Database Adapter and Connector once to my project? Ta
0
263
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 setup properly? Public Class OracleSnapshot Private Shared m_instance As OracleSnapshot Private Sub New() Try
1
9651
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 and I was wondering if anyone here would be able to give me some tips for young players such as myself, for learning the language. Is this the best Newsgroup for support with JAVA?
1
54531
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 we instruct our experts to ignore any such PMs completely Be sure to give the version of Access that you are working with and the Platform and OS if applicable.
1
20274
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 field using (SqlDataReader reader = cmd.ExecuteReader(CommandBehavior.SequentialAccess)) { if (reader.Read())
4
1332
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 in the XML. (I did try adding a set method in my settings.cs to allow me to update the application scoped databaseconnection string, but VS was not being foole d by that). However, I want to change my DatabaseConnection string (to point at a...
0
9566
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9393
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10007
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9946
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8830
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6646
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5413
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3530
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2800
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.