From 5fc857449011f76ed7677aad40576790310d23e1 Mon Sep 17 00:00:00 2001 From: ilotterytea Date: Sun, 20 Apr 2025 16:06:19 +0500 Subject: feat: moved from SQLite to MySQL --- public/emotes/index.php | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) (limited to 'public/emotes/index.php') diff --git a/public/emotes/index.php b/public/emotes/index.php index b603cc0..b981a26 100644 --- a/public/emotes/index.php +++ b/public/emotes/index.php @@ -1,19 +1,24 @@ prepare("SELECT * FROM emotes ORDER BY created_at ASC LIMIT :limit OFFSET :offset"); - $stmt->bindValue(":offset", $page * $limit, SQLITE3_INTEGER); - $stmt->bindValue(":limit", $limit, SQLITE3_INTEGER); - $results = $stmt->execute(); + $offset = $page * $limit; + $db = new PDO(DB_URL, DB_USER, DB_PASS); + $stmt = $db->prepare("SELECT * FROM emotes ORDER BY created_at ASC LIMIT ? OFFSET ?"); + $stmt->bindParam(1, $limit, PDO::PARAM_INT); + $stmt->bindParam(2, $offset, PDO::PARAM_INT); + $stmt->execute(); $emotes = []; - while ($row = $results->fetchArray()) { + $rows = $stmt->fetchAll(); + + foreach ($rows as $row) { array_push($emotes, new Emote( $row["id"], $row["code"], @@ -28,12 +33,13 @@ function display_list_emotes(int $page, int $limit): array function display_emote(int $id) { - $db = new SQLite3("../../database.db"); - $stmt = $db->prepare("SELECT * FROM emotes WHERE id = :id"); - $stmt->bindValue(":id", $id, SQLITE3_INTEGER); - $results = $stmt->execute(); + $db = new PDO(DB_URL, DB_USER, DB_PASS); + $stmt = $db->prepare("SELECT * FROM emotes WHERE id = ?"); + $stmt->execute([$id]); + + $emote = null; - if ($row = $results->fetchArray()) { + if ($row = $stmt->fetch()) { $emote = new Emote( $row["id"], $row["code"], -- cgit v1.2.3