dblink = new mysqli($this->host, $this->user, $this->pwd, $this->dbname); if ($obj->connect_error) { dolog('connect to db0 failed'); die('connect to db failed'); } $this->dblink->query("set names utf8"); } public static function getinstance() { if (!(self::$instance instanceof self)) { self::$instance = new self(); } return self::$instance; } public function exec_db($sql) { // dolog($sql); $rs = $this->dblink->query($sql) or die(dolog($_SERVER['QUERY_STRING']."\n".$this->dblink->error, $sql)); return $rs; } public function exec_db_insertid($sql) { $rs = $this->dblink->query($sql) or die(dolog($_SERVER['QUERY_STRING']."\n".$this->dblink->error, $sql)); return $this->dblink->insert_id; } public function getonerecord($sql) { // dolog($sql); $result = $this->dblink->query($sql) or die(dolog($_SERVER['QUERY_STRING']."\n".$this->dblink->error, $sql)); $data = $result->fetch_all(MYSQLI_ASSOC); mysqli_free_result($result); return $data[0]; } public function close() { // dolog('close db link'); if ($this->dblink) { mysqli_close($this->dblink); } } private function __clone() {} public function __destruct() { $this->close(); } } ?>