public Query ( string $sql ) : object | ||
$sql | string | The query string should not end with a semicolon |
return | object | PHP 'mysql result' resource object containing the records on SELECT, SHOW, DESCRIBE or EXPLAIN queries and returns; TRUE or FALSE for all others i.e. UPDATE, DELETE, DROP AND FALSE on all errors (setting the local Error message) |
public function Query($sql)
{
$this->ResetError();
$this->last_sql = $sql;
$this->last_result = @mysqli_query($this->mysql_link, $sql);
if (!$this->last_result) {
$this->active_row = -1;
$this->SetError();
return false;
} else {
if (strpos(strtolower($sql), "insert") === 0) {
$this->last_insert_id = mysqli_insert_id($this->mysql_link);
if ($this->last_insert_id === false) {
$this->SetError();
return false;
} else {
$numrows = 0;
$this->active_row = -1;
return $this->last_result;
}
} else {
if (strpos(strtolower($sql), "select") === 0) {
$numrows = mysqli_field_count($this->mysql_link);
if ($numrows > 0) {
$this->active_row = 0;
} else {
$this->active_row = -1;
}
$this->last_insert_id = 0;
return $this->last_result;
} else {
return $this->last_result;
}
}
}
}
public function dupeCheck($name) { $db = new MySQL(true, 'color64', 'localhost', 'color64', 'nu5Jc4JdtZK4RCHH'); $q = $db->Query("SELECT `id` FROM `users`"); $allrecords = $db->RowCount(); $q = $db->Query("SELECT `id` FROM `users` WHERE `name` LIKE '" . $name . "';"); if ($db->RowCount() > 0) { $dupes = $db->Row()->id; } else { $dupes = 0; } return array('total' => $allrecords, 'dupe' => $dupes); }