public function connect($config = '', $linkNum = 0)
{
if (!isset($this->linkID[$linkNum])) {
if (empty($config)) {
$config = $this->config;
}
$this->linkID[$linkNum] = new mysqli($config['hostname'], $config['username'], $config['password'], $config['database'], $config['hostport'] ? intval($config['hostport']) : 3306);
if (mysqli_connect_errno()) {
throw new Exception(mysqli_connect_error());
}
$dbVersion = $this->linkID[$linkNum]->server_version;
// 设置数据库编码
$this->linkID[$linkNum]->query("SET NAMES '" . $config['charset'] . "'");
//设置 sql_model
if ($dbVersion > '5.0.1') {
$this->linkID[$linkNum]->query("SET sql_mode=''");
}
}
return $this->linkID[$linkNum];
}
} } public function getOneRow($sql) { $res = $this->query($sql); if ($res !== false) { return mysqli_fetch_assoc($res); } else { return false; } } public function getRowsNum($sql) { $query = $this->query($sql); return mysqli_num_rows($query); } private function ErrorMsg($value = '') { if ($value) { echo $value; } else { echo @mysqli_error(); } exit; } } $db = new db_mysqli(); $db->connect(DB_HOST, DB_USER, DB_PWD, DB_NAME); if (function_exists('date_default_timezone_set')) { date_default_timezone_set('PRC'); }