public static function setInstance($user, $password, $host, $dbName) { if (self::$inst == null) { self::$inst = new self($user, $password, $host, $dbName); } return self::$inst; }
/** * @return Db */ public static function getInstance() { // Exemplo de Singleton if (!self::$instance) { self::$instance = new self(); } return self::$instance; }
public static function setInstance($user, $password, $host, $dbName) { if (self::$inst == null) { self::$inst = new self($user, $password, $host, $dbName); // self::$inst->query('set names utf8'); } return self::$inst; }
/** * 实例化 * @param string $type * @param array $config * @return object eg. Ssdb Redis... */ public static function getInstance($type, $config) { if (!self::$instance instanceof BaseDb) { $class = 'Database\\' . ucfirst($type); if (class_exists($type)) { self::$instance = new $class((array) $config); } else { self::$instance = null; } } return self::$instance; }