Tag Archives: wjdb

MySQL database class using Singleton design pattern

(Note: The following is a revised tutorial I wrote earlier this year, transferred from one of my old web sites.)

Using the Singleton design pattern is a simple way to limit the number of class instances to one, helps keep database connections organized, and can also save memory.  The PHP code below is a basic example on how to use the Singleton pattern to create a database class.  This class can be used to manage a database connection throughout PHP script execution.  While this is a basic example, many improvements have been made over the original version.  If this is well received, we will be happy to add additional functionality. Click read more to view the class, and learn about the functionality of each part. Continue reading MySQL database class using Singleton design pattern