PHP5 PDO Singleton Class

I use Zend Studio for Eclipse as my PHP IDE. The framework I am developing uses PHP PDO for the database abstraction, and rather than passing around a reference to my PDO instance I wanted to create a singleton.

At the same time, I wanted to take advantage of the helpful code completion and suggestion features of the Zend IDE. So I created a class that creates a PDO singleton object in a way that Zend Studio for Eclipse can still do code assistance.

Usage Example

$dbObj =& new sdb("mysql:host=localhost;dbname=testdb", 'username', 'password');

This create a connection to the mysql database 'testdb' and a new PDO instance. $dbOjb can be passed around by reference but using the sdb:: singleton is recommended as Zend will do code assist on this.

Download PDO Singleton Class

The class can be downloaded here: PDO Singleton PHP Class