Location: PHPKode > projects > Thin PHP Framework > ngduc-Thin-PHP-Framework-d63ea45/app/model/base/DBFactory.php
<?php
/**
 * Thin PHP Framework (TPF) 2011-2012 http://thinphp.com
 * @package       app.model.base
 * @license       TPF License http://bit.ly/TPFLicense
 */
defined('BASE') or exit('Direct script access is not allowed!');
require_once BASE.'/app/model/base/driver/DBPdoMysql.php';
require_once BASE.'/app/model/base/driver/DBPdoSqlite.php';

abstract class DBFactory
{
	// Singleton pattern.
	static $dbh;
	
	/**
	 * @return Database Handler
	 */
	public static function getDBHandler()
	{
		global $db_i;
		$dbenv = $db_i[$db_i['env']];
		
		switch ($dbenv['dbdriver'])
		{
			case DB_PDO_MYSQL:
				if ( !isset(self::$dbh) )
				{
					$ret = new DBPdoMysql($dbenv);
					self::$dbh = $ret->getDBHandler();					
					return self::$dbh;
				}
				return self::$dbh;
			case DB_PDO_SQLITE:
				if ( !isset(self::$dbh) )
				{
					$ret = new DBPdoSqlite($dbenv);
					self::$dbh = $ret->getDBHandler();					
					return self::$dbh;
				}
				return self::$dbh;
		}
		return null;
	}
}
Return current item: Thin PHP Framework