]> git.wh0rd.org - tt-rss.git/commitdiff
more pdo stuff i guess
authorAndrew Dolgov <noreply@madoka.volgo-balt.ru>
Fri, 1 Dec 2017 09:42:18 +0000 (12:42 +0300)
committerAndrew Dolgov <noreply@madoka.volgo-balt.ru>
Fri, 1 Dec 2017 09:42:18 +0000 (12:42 +0300)
include/functions.php

index 58f4ba31cdc172bfc8412cc61d79a00a8dc4f7ed..2c93745bbb608b3cec4fd1b964307d8b54e26bcb 100644 (file)
 
                $u_sth = $pdo->prepare("SELECT pref_name
                        FROM ttrss_user_prefs WHERE owner_uid = :uid AND 
-                               (:profile IS NULL AND profile is NULL OR profile = :profile)");
-               $u_sth->execute(['uid' => $uid, 'profile' => $profile]);
+                               profile = :profile OR (:profile IS NULL AND profile IS NULL)");
+               $u_sth->execute([':uid' => $uid, ':profile' => $profile]);
 
                $active_prefs = array();
 
 
                ////db_query("BEGIN");
 
-               if ($parent_cat_id) {
-                       $parent_qpart = "parent_cat = '$parent_cat_id'";
-                       $parent_insert = "'$parent_cat_id'";
-               } else {
-                       $parent_qpart = "parent_cat IS NULL";
-                       $parent_insert = "NULL";
-               }
-
                $feed_cat = mb_substr($feed_cat, 0, 250);
 
                $pdo = Db::pdo();
 
                $sth = $pdo->prepare("SELECT id FROM ttrss_feed_categories
-                               WHERE parent_cat = ? AND title = '$feed_cat' AND owner_uid = ?");
+                               WHERE (:parent IS NULL AND parent_cat IS NULL OR parent_cat = :parent) 
+                               AND title = :cat AND owner_uid = :uid");
+               $sth->execute([':parent' => $parent_cat_id, ':title' => $feed_cat, ':uid' => $_SESSION['uid']]);
 
-               if (db_num_rows($result) == 0) {
+               if ($sth->fetch()) {
 
-                       $result = db_query(
-                               "INSERT INTO ttrss_feed_categories (owner_uid,title,parent_cat)
-                                       VALUES ('".$_SESSION["uid"]."', '$feed_cat', $parent_insert)");
+                       $sth = $pdo->prepare("INSERT INTO ttrss_feed_categories (owner_uid,title,parent_cat)
+                                       VALUES (?, ?, ?)");
+                       $sth->execute([$_SESSION['uid'], $feed_cat, $parent_cat_id]);
 
-                       db_query("COMMIT");
+                       //db_query("COMMIT");
 
                        return true;
                }