PHP 5: MySQL Singleton Example

What is a Singleton?

In software engineering, the singleton pattern is a design pattern that is used to restrict instantiation of a class to one object. This is useful when exactly one object is needed to coordinate actions across the system. Sometimes it is generalized to systems that operate more efficiently when only one or a few objects exist.

Here is a good example of using a Singleton.

Basically, after including your class, you can do something like this:

include_once("MysqlDb.php");
MysqlDB::getInstance()->select("SELECT * FROM `help_category` LIMIT 5");

Subscribe to comments Comment | Trackback |
Post Tags: , , ,

Browse Timeline


Add a Comment


XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong> <pre lang="" line="">


© Copyright 2007 eKini: Web Developer Blog . Thanks for visiting!