magic_quotes = get_magic_quotes_runtime(); if (strpos($dbhost, ':') !== false) { list($host, $port) = explode(':', $dbhost, 2); preg_match('/^([0-9]*)([^0-9]*.*)$/', $port, $socks); $this->connect = mysqli_connect($host, $dbuser, $dbpass, $dbname, $socks[1] ? $socks[1] : null, $socks[2] ? $socks[2] : null); } else $this->connect = mysqli_connect($dbhost, $dbuser, $dbpass, $dbname); if (!$this->connect) $this->error('Connection error. Can not connect to database'); $this->connect->set_charset($dbencoding); if ($this->connect->error) $this->error($this->connect->error); if (Xcrud_config::$db_time_zone) $this->connect->query('SET time_zone = \'' . Xcrud_config::$db_time_zone . '\''); } public function query($query = '') { $this->result = $this->connect->query($query, MYSQLI_USE_RESULT); //echo '
' . $query . '
'; if ($this->connect->error) $this->error($this->connect->error . '
' . $query . '
'); return $this->connect->affected_rows; } public function insert_id() { return $this->connect->insert_id; } public function result() { $out = array(); if ($this->result) { while ($obj = $this->result->fetch_assoc()) { $out[] = $obj; } $this->result->free(); } return $out; } public function row() { $obj = $this->result->fetch_assoc(); $this->result->free(); return $obj; } public function escape($val, $not_qu = false, $type = false, $null = false, $bit = false) { if ($type) { switch ($type) { case 'bool': if ($bit) { return (int)$val ? 'b\'1\'' : 'b\'0\''; } return (int)$val ? 1 : ($null ? 'NULL' : 0); break; case 'int': $val = preg_replace('/[^0-9\-]/', '', $val); if ($val === '') { if ($null) { return 'NULL'; } else { $val = 0; } } if ($bit) { return 'b\'' . $val . '\''; } return $val; break; case 'float': if ($val === '') { if ($null) { return 'NULL'; } else { $val = 0; } } return '\'' . $val . '\''; break; default: if (trim($val) == '') { if ($null) { return 'NULL'; } else { return '\'\''; } } else { if ($type == 'point') { $val = preg_replace('[^0-9\.\,\-]', '', $val); } //return '\'' . ($this->magic_quotes ? (string )$val : $this->connect->real_escape_string((string )$val)) . '\''; } break; } } if ($not_qu) return $this->magic_quotes ? (string )$val : $this->connect->real_escape_string((string )$val); return '\'' . ($this->magic_quotes ? (string )$val : $this->connect->real_escape_string((string )$val)) . '\''; } public function escape_like($val, $pattern = array('%', '%')) { if (is_int($val)) return '\'' . $pattern[0] . (int)$val . $pattern[1] . '\''; if ($val == '') { return '\'\''; } else { return '\'' . $pattern[0] . ($this->magic_quotes ? (string )$val : $this->connect->real_escape_string((string )$val)) . $pattern[1] . '\''; } } private function error($text = 'Error!') { exit('
Error' . $text.'ERROR, probably duplicate value or BLANK value ' . '
'); //$text } }