Fix requesting updates or messages with invalid parameters.

parent 0806b5a3
...@@ -185,23 +185,28 @@ class DB ...@@ -185,23 +185,28 @@ class DB
} }
try { try {
$sql = 'SELECT `id` FROM `' . TB_TELEGRAM_UPDATE . '`'; $sql = '
SELECT `id`
FROM `' . TB_TELEGRAM_UPDATE . '`
';
if ($id !== null) { if ($id !== null) {
$sql .= ' WHERE `id` = :id'; $sql .= ' WHERE `id` = :id';
} else {
$sql .= ' ORDER BY `id` DESC';
} }
$sql .= ' ORDER BY `id` DESC';
if ($limit !== null) { if ($limit !== null) {
$sql .= ' LIMIT :limit'; $sql .= ' LIMIT :limit';
} }
$sth = self::$pdo->prepare($sql); $sth = self::$pdo->prepare($sql);
$sth->bindParam(':limit', $limit, PDO::PARAM_INT);
if ($limit !== null) {
$sth->bindValue(':limit', $limit, PDO::PARAM_INT);
}
if ($id !== null) { if ($id !== null) {
$sth->bindParam(':id', $id, PDO::PARAM_STR); $sth->bindValue(':id', $id);
} }
$sth->execute(); $sth->execute();
...@@ -230,16 +235,19 @@ class DB ...@@ -230,16 +235,19 @@ class DB
$sql = ' $sql = '
SELECT * SELECT *
FROM `' . TB_MESSAGE . '` FROM `' . TB_MESSAGE . '`
WHERE `update_id` != 0 ORDER BY `id` DESC
ORDER BY `message_id` DESC
'; ';
if ($limit !== null) { if ($limit !== null) {
$sql .= 'LIMIT :limit'; $sql .= ' LIMIT :limit';
} }
$sth = self::$pdo->prepare($sql); $sth = self::$pdo->prepare($sql);
$sth->bindParam(':limit', $limit, PDO::PARAM_INT);
if ($limit !== null) {
$sth->bindValue(':limit', $limit, PDO::PARAM_INT);
}
$sth->execute(); $sth->execute();
return $sth->fetchAll(PDO::FETCH_ASSOC); return $sth->fetchAll(PDO::FETCH_ASSOC);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment