HomePHP Working with MySQL and Sessions to Serialize Objects in PHP
Working with MySQL and Sessions to Serialize Objects in PHP
If you're interested in learning how to combine objects, sessions and MySQL, this is the article that you’ve been waiting for. It's the final part of the series “Serializing objects in PHP.” In three parts, this series goes through the fundamentals of serializing objects in PHP applications, and explores some advanced topics with regard to this subject, including the use of the magic “__sleep()” and “__wakeup()” functions, and the manipulation of serialized objects inside of MySQL tables.
If you’ve been reading the previous tutorials, then you’ve hopefully learned the basics of how to serialize/unserialize objects in PHP, as well as how to use the combination of “__sleep()” and “__wakeup()” functions to create objects that are capable of maintaining their state across different web page requests. As you’ll probably recall, these types of objects are called persisting objects, and in general terms, are constructed without the need to use the PHP built-in session handling mechanism.
Aside from the practical implementation of serialization for building persisting objects, it should be noted that there’s plenty of room to use serialized objects in Web applications, either as part of more advanced programming approaches, or in order to achieve something as simple as storing objects in text files and cookies. Once you’ve mastered the concepts behind object serialization, you can go ahead and develop several applications (an object caching system, to cite an illustrative example), which use serialization for achieving some basic tasks.
Provided that you’ve already grasped the key concepts about object serialization, in addition to implementing some advanced features, such as the ones I mentioned right at the beginning of this article, in this final installment of the series, I’ll show you some examples of how to work with objects and sessions. I'll also show you how to use MySQL tables to keep your objects safe and healthy.
So, are you interested in learning how to combine objects, sessions and MySQL? Let’s start exploring this powerful combination.