]> git.wh0rd.org - tt-rss.git/commitdiff
sessions: PDO
authorAndrew Dolgov <noreply@madoka.volgo-balt.ru>
Fri, 1 Dec 2017 11:48:23 +0000 (14:48 +0300)
committerAndrew Dolgov <noreply@madoka.volgo-balt.ru>
Fri, 1 Dec 2017 11:48:23 +0000 (14:48 +0300)
include/functions.php
include/sessions.php

index e366a49650306d93a849f4a9896681608dadff1b..07f4f0f641023488d5aca5ba2720485ba8444c07 100644 (file)
                $pdo = Db::pdo();
 
                $sth = $pdo->prepare("SELECT owner_uid FROM ttrss_feeds WHERE id = ?");
-               $sth->execute($feed_id);
+               $sth->execute([$feed_id]);
 
                $owner_uid = false;
 
index 7ea9052bc71307c19b2a5da62bcc716fc7341c76..c80c21de3a24cc6314f4fe8164c0313363f29cfb 100644 (file)
                global $schema_version;
 
                if (!$schema_version) {
-                       $result = Db::get()->query("SELECT schema_version FROM ttrss_version");
-                       $version = Db::get()->fetch_result($result, 0, "schema_version");
+                       $row = Db::pdo()->query("SELECT schema_version FROM ttrss_version")->fetch();
+
+                       $version = $row["schema_version"];
+
                        $schema_version = $version;
                        return $version;
                } else {
                                __("Session failed to validate (schema version changed)");
                        return false;
                }
+        $pdo = Db::pdo();
 
                if ($_SESSION["uid"]) {
-                       $result = Db::get()->query(
-                               "SELECT pwd_hash FROM ttrss_users WHERE id = '".$_SESSION["uid"]."'");
+                       $sth = $pdo->prepare("SELECT pwd_hash FROM ttrss_users WHERE id = ?");
+                       $sth->execute([$_SESSION['uid']]);
 
                        // user not found
-                       if (Db::get()->num_rows($result) == 0) {
+                       if ($row = $sth->fetch()) {
+                $pwd_hash = $row["pwd_hash"];
+
+                if ($pwd_hash != $_SESSION["pwd_hash"]) {
 
-                               $_SESSION["login_error_msg"] =
-                                       __("Session failed to validate (user not found)");
+                    $_SESSION["login_error_msg"] =
+                        __("Session failed to validate (password changed)");
 
-                               return false;
+                    return false;
+                }
                        } else {
-                               $pwd_hash = Db::get()->fetch_result($result, 0, "pwd_hash");
 
-                               if ($pwd_hash != $_SESSION["pwd_hash"]) {
+                $_SESSION["login_error_msg"] =
+                    __("Session failed to validate (user not found)");
 
-                                       $_SESSION["login_error_msg"] =
-                                               __("Session failed to validate (password changed)");
+                return false;
 
-                                       return false;
-                               }
                        }
                }
 
        function ttrss_read ($id){
                global $session_expire;
 
-               $res = Db::get()->query("SELECT data FROM ttrss_sessions WHERE id='$id'");
+               $sth = Db::pdo()->prepare("SELECT data FROM ttrss_sessions WHERE id=?");
+               $sth->execute([$id]);
 
-               if (Db::get()->num_rows($res) != 1) {
+               if ($row = $sth->fetch()) {
+            return base64_decode($row["data"]);
 
-                       $expire = time() + $session_expire;
+               } else {
+            $expire = time() + $session_expire;
 
-                       Db::get()->query("INSERT INTO ttrss_sessions (id, data, expire)
-                                       VALUES ('$id', '', '$expire')");
+            $sth = Db::pdo()->prepare("INSERT INTO ttrss_sessions (id, data, expire)
+                                       VALUES (?, '', ?)");
+            $sth->execute([$id, $expire]);
+
+            return "";
 
-                       return "";
-               } else {
-                       return base64_decode(Db::get()->fetch_result($res, 0, "data"));
                }
 
        }
                $data = base64_encode($data);
                $expire = time() + $session_expire;
 
-               Db::get()->query("UPDATE ttrss_sessions SET data='$data', expire='$expire' WHERE id='$id'");
+        $sth = Db::pdo()->prepare("UPDATE ttrss_sessions SET data=?, expire=? WHERE id=?");
+        $sth->execute([$data, $expire, $id]);
 
                return true;
        }
        }
 
        function ttrss_destroy($id) {
-               Db::get()->query("DELETE FROM ttrss_sessions WHERE id = '$id'");
+               $sth = Db::pdo()->prepare("DELETE FROM ttrss_sessions WHERE id = ?");
+               $sth->execute([$id]);
 
                return true;
        }
         * @SuppressWarnings(PHPMD.UnusedFormalParameter)
         */
        function ttrss_gc ($expire) {
-               Db::get()->query("DELETE FROM ttrss_sessions WHERE expire < " . time());
+               Db::pdo()->query("DELETE FROM ttrss_sessions WHERE expire < " . time());
 
                return true;
        }