示例#1
0
	/**
	 * 获取db
	 *@return MySql
	 */
	public static function getDb($dbname = NULL, $dbClassName = 'MySql')
	{
		if (null == $dbname) {
			$dbId = $dbClassName.':default';
			$config = SuiShiPHPConfig::genDbConfig(C('DB_HOST'), C('DB_USER'), C('DB_PASSWORD'), C('DB_NAME'));
		} else {
			$dbId = $dbClassName.':'.$dbname;
			$config = SuiShiPHPConfig::getDbConfig($dbname);
		}
		
		if (!$config) {
			return null;
		}
		if (!isset(self::$DBS[$dbId])) {
			$db = new $dbClassName($config['DB_HOST'], $config['DB_USER'], $config['DB_PWD'], $config['DB_NAME']);
			self::$DBS[$dbId] = $db;
		}
		return self::$DBS[$dbId];
	}