protected function getMessageQueryErr($result, $nameFunc) { if (!$result) { return false; exit("error of database \n" . DB::getMySQLiObject()->error . " in a method: " . $nameFunc); } return true; }
public static function getComments($id_article, $start, $step) { $result = DB::query("SELECT id_comment, author, text, date FROM comments WHERE id_article={$id_article} ORDER BY date DESC limit {$start},{$step} "); if (!$result) { exit("error of database \n" . DB::getMySQLiObject()->error); } $response = array(); while ($comment = $result->fetch_assoc()) { $response[] = $comment; } //print_r($response); return $response; }
public static function getArticles($start, $step) { $result = DB::query("SELECT id, title, description, date, img_src FROM articles ORDER BY date DESC limit {$start},{$step} "); /*$count = DB::query("SELECT COUNT(*) FROM articles"); $count=$count->fetch_assoc()['COUNT(*)'];*/ if (!$result) { exit("error of database \n" . DB::getMySQLiObject()->error); } $response = array(); while ($article = $result->fetch_assoc()) { $response[] = $article; } return $response; }
public function create() { $q = "SELECT id,name FROM roles WHERE name = '" . DB::esc($this->role) . "'"; $dbresult = DB::query($q); if ($dbresult->num_rows == 1) { $role_result = $dbresult->fetch_array(); $this->role_id = $role_result['id']; } else { throw new Exception('unknown chat'); } DB::query("\r\n INSERT INTO chatlines (user_id, text, role_id, created)\r\n\t\t\tVALUES (\r\n\t\t\t " . DB::esc($this->user_id) . ",\r\n\t\t\t '" . DB::esc($this->text) . "',\r\n\t\t\t " . DB::esc($this->role_id) . ",\r\n\t\t\t NOW()\r\n\t\t\t)"); // Returns the MySQLi object of the DB class $this->id = DB::getMySQLiObject()->insert_id; return $this->id; }
protected function handlerForm() { $id = $_POST['id']; $title = $_POST['title']; if (empty($title)) { exit("Не заполнены обязательные поля"); } $query = " UPDATE category SET name_category='{$title}' WHERE id_category='{$id}'"; $result = DB::query($query); if ($this->getMessageQueryErr($result, __FUNCTION__) && DB::getMySQLiObject()->affected_rows != -1) { $_SESSION['result'] = "Изменения сохранены"; header("Location:?option=edit_category"); exit; } else { exit("Error during editing"); } }
public function getDetails() { $q = "SELECT r.id AS id, u.username AS user1, v.username AS user2, w.name AS grp, title, text, completed, begin, end, created, modified\n FROM reminders AS r \n LEFT OUTER JOIN users AS u ON r.user_id = u.id\n LEFT OUTER JOIN users AS v ON r.backup_user_id = v.id\n LEFT OUTER JOIN roles AS w ON r.group_id = w.id\n WHERE r.id = " . DB::esc($this->id); $results = DB::query($q); if (!$results) { throw new Exception(DB::getMySQLiObject()->error); } $output = null; if ($results) { while ($output[] = mysqli_fetch_assoc($results)) { } } if (!is_null($output) && end($output) == null) { array_pop($output); } return $output; }
public function handlerForm() { if ($_GET['del']) { $id_category = (int) $_GET['del']; $query = "DELETE FROM category WHERE id_category='{$id_category}'"; $result = DB::query($query); if ($this->getMessageQueryErr($result, __FUNCTION__) && DB::getMySQLiObject()->affected_rows != 0) { $_SESSION['result'] = "Удалено"; header("Location:?option=edit_category"); exit; } else { exit("Error during deleting"); } } else { exit("Wrong id article"); } }
public function handle() { $q = "UPDATE sms SET handled_at = NOW(), handled_by = " . DB::esc($this->handled_by) . " WHERE id = " . DB::esc($this->id); $res = DB::query($q); if (!$res) { throw new Exception(DB::getMySQLiObject()->error); } }
public function save() { DB::query("\r\n\t\t\tINSERT INTO webchat_lines (author, gravatar, text)\r\n\t\t\tVALUES (\r\n\t\t\t\t'" . DB::esc($this->author) . "',\r\n\t\t\t\t'" . DB::esc($this->gravatar) . "',\r\n\t\t\t\t'" . DB::esc($this->text) . "'\r\n\t\t)"); // Returns the MySQLi object of the DB class return DB::getMySQLiObject(); }
public function save() { DB::query("\n\t\t\tINSERT INTO webchat_lines (author, gravatar, text, room, room_do, tss, czyt)\n\t\t\tVALUES (\n\t\t\t\t'" . DB::esc($this->author) . "',\n\t\t\t\t'" . DB::esc($this->gravatar) . "',\n\t\t\t\t'" . DB::esc($this->text) . "',\n\t\t\t\t'" . $this->room . "',\n\t\t\t\t'" . $this->room_od . "',\n\t\t\t\t'" . time() . "',\n\t\t\t\t'" . $this->czyt . "'\n\t\t)"); // Returns the MySQLi object of the DB class return DB::getMySQLiObject(); }
public function setTicket($tick_no) { $q = "UPDATE messages SET ticket_id = " . DB::esc($tick_no) . "\n WHERE id = " . DB::esc($this->id); $res = DB::query($q); if (!$res) { throw new Exception(DB::getMySQLiObject()->error); } }
public function clearNotification() { $q = "UPDATE updates SET updated = 0 WHERE id = " . DB::$this->id; $res = DB::query($q); if (!$res) { throw new Exception(DB::getMySQLiObject()->error); } }
public function save() { DB::query("\r\n INSERT INTO webchat_lines (author, gravatar, text)\r\n VALUES (\r\n '" . DB::esc($this->author) . "',\r\n '" . DB::esc($this->gravatar) . "',\r\n '" . DB::esc($this->text) . "'\r\n )"); // Возвращаем объект MySQLi класса DB return DB::getMySQLiObject(); }
public function create() { DB::query("\r\n\t\t\tINSERT INTO users (username, password, role_id)\r\n\t\t\tVALUES (\r\n\t\t\t\t'" . DB::esc($this->username) . "',\r\n\t\t\t\t'" . hash('sha1', DB::esc($this->password)) . "',\r\n '" . DB::esc($this->role_id) . "'\r\n )\r\n "); $this->id = DB::getMySQLiObject()->insert_id; return $this->id; }
public function clearNotification() { $count_upd = 0; $q_upd = "select count(updated) from updates where ticket_id = " . DB::esc($this->id) . " AND updated=1"; $res_upd = DB::query($q_upd); if ($res_upd) { $count_row_upd = mysqli_fetch_assoc($res_upd); $count_upd = $count_row_upd['count(updated)']; } $count_mes = 0; $q_mes = "select count(updated) from messages where ticket_id = " . DB::esc($this->id) . " AND updated=1"; $res_mes = DB::query($q_mes); if ($res_mes) { $count_row_mes = mysqli_fetch_assoc($res_mes); $count_mes = $count_row_mes['count(updated)']; } if ($count_upd + $count_mes == 0) { $q_clear = "UPDATE tickets SET updated = 0, modified = '" . date('Y-m-d G:i:s') . "' WHERE id = " . DB::esc($this->id) . ""; $res = DB::query($q_clear); if (!$res) { throw new Exception(DB::getMySQLiObject()->error); } } }
$message = "Upload error: " . $_FILES["file"]["error"]; } else { DB::init($dbOptions); $row = 1; if (($handle = fopen($_FILES["file"]["tmp_name"], "r")) !== FALSE) { while (($data = fgetcsv($handle)) !== FALSE) { $num = count($data); $row++; if ($num == 3) { $q = "SELECT count(1) FROM groups WHERE name = '{$data['0']}'"; $res = DB::query($q); $row = $res->fetch_assoc(); if ($row['count(1)'] == 0) { $q = "INSERT INTO groups (name) VALUES ('{$data['0']}')"; $res = DB::query($q); $id = DB::getMySQLiObject()->insert_id; $q = "INSERT INTO handles (handle_name, description, group_id) VALUES ('{$data['2']}', '{$data['1']}', {$id})"; DB::query($q); } else { $q = "SELECT id FROM groups WHERE name = '{$data['0']}'"; debug($q); $res = DB::query($q); $row = $res->fetch_assoc(); $q = "INSERT INTO handles (handle_name, description, group_id) VALUES ('{$data['2']}', '{$data['1']}', {$row['id']})"; debug($q); DB::query($q); } } } fclose($handle); }
public function save() { DB::query("\r\n INSERT INTO webchat_users (name, gravatar)\r\n VALUES (\r\n '" . DB::esc($this->name) . "',\r\n '" . DB::esc($this->gravatar) . "'\r\n )"); return DB::getMySQLiObject(); }
protected function handlerForm() { $article = $this->getArticle($_GET['id_article']); //need to existing save images if (!empty($_FILES['img_src']['tmp_name'])) { if (!move_uploaded_file($_FILES['img_src']['tmp_name'], 'images/' . $_FILES['img_src']['name'])) { exit("Не удалось загрузить изображение"); } $img_src = 'images/' . $_FILES['img_src']['name']; } else { $img_src = $article[img_src]; //echo "$img_src"; } $id = $_POST['id']; $title = $_POST['title']; $date = date("y-m-d", time()); $description = $_POST['description']; $text = $_POST['text']; $category = $_POST['category']; if (empty($title) || empty($text) || empty($description)) { exit("Не заполнены обязательные поля"); } $query = " UPDATE articles SET title='{$title}', img_src='{$img_src}', date='{$date}', text='{$text}', description='{$description}', category='{$category}' WHERE id='{$id}'"; $result = DB::query($query); if ($this->getMessageQueryErr($result, __FUNCTION__) && DB::getMySQLiObject()->affected_rows != -1) { $_SESSION['result'] = "Изменение сохранены"; header("Location:?option=admin"); exit; } else { exit("Error during editing"); } }