MySQLiConnect(); } protected function MySQLiConnect() { $db = mysqli_connect("127.0.0.1", "root", "123456", "site0") or die("Error! " . mysqli_error($db)); $this->db = $db; $this->query('SET names utf8'); } public function fetch($res) { return mysqli_fetch_assoc($res); } public function query($string) { $this->queryCount++; $startQueryTime = microtime(true); $q = mysqli_query($this->db, $string); $endQueryTime = microtime(true); $this->queryTotalTime += $endQueryTime - $startQueryTime; $this->queries[] = $string; $this->log .= "\r\n[" . microtime(true) . "] " . $string . " - " . (round($endQueryTime - $startQueryTime) * 1000) . " мс."; return $q; } public function insert_id() { return mysqli_insert_id($this->db); } public function filter($string) { if (gettype($string) == "string") return mysqli_real_escape_string($this->db, $string); else return $string; } public function num_rows($res) { return mysqli_num_rows($res); } public function error() { return mysqli_error($this->db); } protected function mysqli_result($res, $row = 0, $col = 0){ if (mysqli_num_rows($res) && $row <= (mysqli_num_rows($res)-1) && $row >= 0){ mysqli_data_seek($res,$row); $resrow = mysqli_fetch_row($res); if (isset($resrow[$col])){ return $resrow[$col]; } } return false; } public function result($res, $row) { return $this->mysqli_result($res, $row); } public function getQueries() { echo $this->queryCount . " SQL-запросов за " . round(($this->queryTotalTime) * 1000) . ' мс'; } } } ?>