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 --- src/accounts.php | 15 +++++++++------ src/config.php | 5 +++++ src/emotes/single_page.php | 14 ++++++++------ 3 files changed, 22 insertions(+), 12 deletions(-) create mode 100644 src/config.php (limited to 'src') diff --git a/src/accounts.php b/src/accounts.php index 4273964..330ad3c 100644 --- a/src/accounts.php +++ b/src/accounts.php @@ -1,4 +1,6 @@ prepare("SELECT id, username FROM users WHERE secret_key = :secret_key"); - $stmt->bindValue("secret_key", $_COOKIE["secret_key"]); - $results = $stmt->execute(); + $stmt = $db->prepare("SELECT id, username FROM users WHERE secret_key = ?"); + $stmt->execute([$_COOKIE["secret_key"]]); - if ($row = $results->fetchArray()) { + if ($row = $stmt->fetch()) { $_SESSION["user_id"] = $row["id"]; $_SESSION["user_name"] = $row["username"]; } else { @@ -25,5 +28,5 @@ function authorize_user() setcookie("secret_key", "", time() - 1000); } - $db->close(); + $db = null; } \ No newline at end of file diff --git a/src/config.php b/src/config.php new file mode 100644 index 0000000..188b7bb --- /dev/null +++ b/src/config.php @@ -0,0 +1,5 @@ + @@ -76,17 +79,16 @@ $link = "#"; if ($emote->get_uploaded_by()) { - $db = new SQLite3("../../database.db"); - $stmt = $db->prepare("SELECT username FROM users WHERE id = :id"); - $stmt->bindValue(":id", $emote->get_uploaded_by()); - $results = $stmt->execute(); + $db = new PDO(DB_URL, DB_USER, DB_PASS); + $stmt = $db->prepare("SELECT username FROM users WHERE id = ?"); + $stmt->execute([$emote->get_uploaded_by()]); - if ($row = $results->fetchArray()) { + if ($row = $stmt->fetch()) { $username = $row["username"]; $link = "/users/" . $emote->get_uploaded_by(); } - $db->close(); + $db = null; } echo ""; -- cgit v1.2.3