PHP MDB2: Creating MDB2 singleton connection within an object

99 Views Asked by At

I am new to Php OOP and I doing research I read that the singleton design for database objects are the preferred method. However, I am lost as to whether this will continue to make new instances of that connection, since I am not directly creating the singleton class but using a framework provided through PEAR?

abstract class WI_Object_DB extends WI_Object {
protected static $cxn;

protected static function init($config){
    self::$cxn =& MDB2::singleton($config->dsn);
    if (!PEAR::isError(self::$cxn)) {
        self::$cxn->setFetchMode('DB_FETCHMODE_ASSOC');
    } else {
        throw new Exception(self::$cxn->getMessage());
    }
}

public function __construct()
{
    parent::__construct();
    if (self::$cxn===null) {
        self::init($GLOBALS['configs']);
    }

}

}

0

There are 0 best solutions below