예제 #1
0
파일: SQLite.php 프로젝트: snje1987/minifw
 /**
  * 私有构造函数
  */
 protected function __construct($args = [])
 {
     parent::__construct();
     $ini = Minifw\Config::get('sqlite');
     if (!empty($args)) {
         $ini['path'] = isset($args['path']) ? strval($args['path']) : $ini['path'];
     }
     if (empty($ini)) {
         throw new Minifw\Exception('数据库未配置');
     }
     $this->_sqlite = new \SQLite3(WEB_ROOT . $ini['path'], SQLITE3_OPEN_READWRITE | SQLITE3_OPEN_CREATE);
 }
예제 #2
0
파일: Mysqli.php 프로젝트: snje1987/minifw
 /**
  * 私有构造函数
  */
 protected function __construct($args = [])
 {
     parent::__construct();
     $ini = Minifw\Config::get('mysql');
     if (!empty($args)) {
         $ini['host'] = isset($args['host']) ? strval($args['host']) : $ini['host'];
         $ini['username'] = isset($args['username']) ? strval($args['username']) : $ini['username'];
         $ini['password'] = isset($args['password']) ? strval($args['password']) : $ini['password'];
         $ini['dbname'] = isset($args['dbname']) ? strval($args['dbname']) : $ini['dbname'];
         $ini['encoding'] = isset($args['encoding']) ? strval($args['encoding']) : $ini['encoding'];
     }
     if (empty($ini)) {
         throw new Minifw\Exception('数据库未配置');
     }
     $this->_host = $ini['host'];
     $this->_username = $ini['username'];
     $this->_password = $ini['password'];
     $this->_dbname = $ini['dbname'];
     $this->_encoding = $ini['encoding'];
     $this->_mysqli = new \mysqli($this->_host, $this->_username, $this->_password, $this->_dbname);
     if ($this->_mysqli->connect_error) {
         throw new Minifw\Exception('数据库连接失败');
     }
     if (!$this->_mysqli->set_charset($this->_encoding)) {
         throw new Minifw\Exception('数据库查询失败');
     }
 }