con = mysql_connect($db_host, $db_user, $db_pass); if($this->con === false) { $this->qError = mysql_error(); $this->conStatus = false; } elseif ($this->selectDB($db_schema) === false) { $this->qError = mysql_error($this->con); $this->conStatus = null; } else { $this->conStatus = true; } } function getCon() { return $this->con; } function selectDB($db_schema) { return mysql_select_db($db_schema, $this->con); } function getError() { return $this->qError; } function getLastQuery() { return $this->lastQuery; } function isConnected() { return $this->conStatus; } function query($string) { Database::$qCount++; $resource = mysql_query($string, $this->con); if ($resource === false) { $this->qError = mysql_error(); } $this->lastQuery = $string; $this->lastResult = $resource; if ($this->autoErrors === true) { $this->ifError(); } return $resource; } function mnr($resource = null) { if (is_null($resource)) { $resource = $this->lastResult; } if (is_resource($resource)) { return mysql_num_rows($resource); } else { return false; } } function mar() { return mysql_affected_rows($this->con); } function fetchArray($resource = null, $constant = MYSQL_NUM) { if (is_null($resource)) { $resource = $this->lastResult; } if (is_resource($resource)) { return mysql_fetch_array($resource, $constant); } else { return false; } } function fetchObject($resource = null, $class_name = null, $params = null) { if (is_null($resource)) { $resource = $this->lastResult; } if (is_resource($resource)) { if (!is_string($class_name)) { return mysql_fetch_object($resource); } elseif (!is_array($params)) { return mysql_fetch_object($resource, $class_name); } else { return mysql_fetch_object($resource, $class_name, $params); } } else { return false; } } function clean($string) { if (get_magic_quotes_gpc()) { $string = stripslashes($string); } $string = mysql_real_escape_string(htmlentities(trim($string))); return $string; } function clean_nl2br($string) { if (get_magic_quotes_gpc()) { $string = stripslashes($string); } $string = mysql_real_escape_string(nl2br(htmlentities(trim($string)))); return $string; } function reuseLastResult($resource = null) { if (is_null($resource)) { $resource = $this->lastResult; } if (is_resource($resource)) { $this->lastResult = mysql_data_seek($resource, 0); } return $this->lastResult; } function escape($string) { if (get_magic_quotes_gpc()) { $string = stripslashes($string); } $string = mysql_real_escape_string(trim($string)); return $string; } function insertId() { return mysql_insert_id($this->con); } function ifError($type = 1) { if ($this->lastResult === false or strlen(mysql_error() > 0)) { decho("Error: $this->qError
Query: $this->lastQuery", $type); } } function toggleErrors($bool) { $this->autoErrors = (bool) $bool; } function __destruct() { if ($this->conStatus !== false) { mysql_close($this->con); $this->conStatus = false; } } } ?>