con = new mysqli($GLOBALS['MYSQL_HOST'],$GLOBALS['MYSQL_USER'],$GLOBALS['MYSQL_PASS'],$GLOBALS['MYSQL_DB'],$GLOBALS['MYSQL_PORT']); if($this->con){ $this->con->set_charset("utf8"); return true; }else{ echo("connect database is error!!".$this->con->connect_error); return false; } } function Query($sql){ return $this->con->query($sql); } function myping(){ return $this->con->ping(); } //开始事务 function BeginRoll(){ return $this->con->autocommit(false); } //退回事务 function RollBack(){ $this->con->rollback(); $this->con->autocommit(true); return true; } //提交事务 function CommitRoll(){ $this->con->commit(); $this->con->autocommit(true); return true; } //结果集的行数 function NumRows($result){ return $result->num_rows; } /** * 执行一条带有结果集计数的 count SQL 语句, 并返该计数. */ function count($sql){ $result = $this->Query($sql); if($row = $this->FetchArray2($result)){ return (int)$row[0]; }else{ return 0; } } //以数字索引返回一行数据 function FetchRow($result){ return $result->fetch_row(); } //返回所有的结果集 function getAll($result){ $tmp_array = array(); while($row = $this->FetchArray($result)){ $tmp_array[] = $row; } return $tmp_array; } //返回一条数据(字段名作key) function getOne($result){ return $this->FetchArray($result); } //返回一条数据(字段名作key) function FetchAssoc($result){ return $result->fetch_assoc(); } //返回一条数据(字段名作key) function FetchArray($result){ return $result->fetch_array(MYSQLI_ASSOC); } //返回一条数据(字段名作以及数字都有key) function FetchArray2($result){ return $result->fetch_array(MYSQLI_BOTH); } //返回一条对像数据(字段名作key) function FetchObject($result){ return $result->fetch_object(); } //释放查询结果内存 function FreeResult($result){ return $result->free(); } //影响行数 function AffectedRows(){ return $this->con->affected_rows; } //复位记录集指针 function DataSeek($result){ return $this->con->data_seek($result,0); } //返回最后插入的自增ID function InsertID(){ return $this->con->insert_id; } function Close(){ if($this->con){ $this->con->close(); } } } ?>