Esempio n. 1
0
 /**
  * 取得数据库类实例
  * @static
  * @access public
  * @param mixed $config 连接配置
  * @param boolean $lite 是否lite方式
  * @return Object 返回数据库驱动类
  */
 public static function instance($config = [], $lite = false)
 {
     $md5 = md5(serialize($config));
     if (!isset(self::$instance[$md5])) {
         // 解析连接参数 支持数组和字符串
         $options = self::parseConfig($config);
         // 如果采用lite方式 仅支持原生SQL 包括query和execute方法
         $class = $lite ? '\\think\\db\\Lite' : '\\think\\db\\driver\\' . ucwords($options['type']);
         self::$instance[$md5] = new $class($options);
     }
     self::$_instance = self::$instance[$md5];
     return self::$_instance;
 }
Esempio n. 2
0
 /**
  * 取得数据库类实例
  * @static
  * @access public
  * @param mixed $config 连接配置
  * @return Object 返回数据库驱动类
  */
 public static function instance($config = [])
 {
     $md5 = md5(serialize($config));
     if (!isset(self::$instances[$md5])) {
         // 解析连接参数 支持数组和字符串
         $options = self::parseConfig($config);
         if (empty($options['type'])) {
             throw new Exception('db type error');
         }
         $class = (!empty($options['namespace']) ? $options['namespace'] : '\\think\\db\\driver\\') . ucwords($options['type']);
         self::$instances[$md5] = new $class($options);
     }
     self::$instance = self::$instances[$md5];
     return self::$instance;
 }
Esempio n. 3
0
 /**
  * 取得数据库类实例
  * @static
  * @access public
  * @param mixed $config 连接配置
  * @param boolean $lite 是否lite方式
  * @return Object 返回数据库驱动类
  */
 public static function instance($config = [], $lite = false)
 {
     $md5 = md5(serialize($config));
     if (!isset(self::$instances[$md5])) {
         // 解析连接参数 支持数组和字符串
         $options = self::parseConfig($config);
         if (empty($options['type'])) {
             throw new Exception('db type error');
         }
         // 如果采用lite方式 仅支持原生SQL 包括query和execute方法
         $class = $lite ? '\\think\\db\\Lite' : (!empty($options['namespace']) ? $options['namespace'] : '\\think\\db\\driver\\') . ucwords($options['type']);
         self::$instances[$md5] = new $class($options);
     }
     self::$instance = self::$instances[$md5];
     return self::$instance;
 }
Esempio n. 4
0
File: Db.php Progetto: 5ini99/think
 /**
  * 数据库初始化 并取得数据库类实例
  * @static
  * @access public
  * @param mixed $config 连接配置
  * @return Object 返回数据库驱动类
  */
 public static function connect($config = [])
 {
     $md5 = md5(serialize($config));
     if (!isset(self::$instances[$md5])) {
         // 解析连接参数 支持数组和字符串
         $options = self::parseConfig($config);
         if (empty($options['type'])) {
             throw new Exception('db type error');
         }
         $class = (!empty($options['namespace']) ? $options['namespace'] : '\\think\\db\\driver\\') . ucwords($options['type']);
         self::$instances[$md5] = new $class($options);
         // 记录初始化信息
         APP_DEBUG && Log::record('[ DB ] INIT ' . $options['type'] . ':' . var_export($options, true), 'info');
     }
     self::$instance = self::$instances[$md5];
     return self::$instance;
 }