Creating a MySQL Database Class Using the Singleton Design Pattern
When creating a database class using mysql, we would create a class, and call it’s constructor in the script.
One potential problem with this approach is that each time we create a new database object, we allocate more and more memory to those operations. In some cases, it might make sense to do it that way, but a lot of times we only need one instance. This will help keep things organized and save memory.
This tutorial is a basic example of how to use the Singleton Pattern to create a database class. This concept makes it easy to stay organized and use a centralized object for all of your database connections. Keep in mind that this is only a very basic level example, and there are many things that can be done to improve this class.
Using the Singleton Pattern is a simple way to limit the number of instances of an object to just one, helps keep database connections organized, and saves memory.
Link: Creating a MySQL Database Class Using the Singleton Design Pattern