]> git.mxchange.org Git - friendica.git/commitdiff
Normalize return value in Database->fetch
authorHypolite Petovan <hypolite@mrpetovan.com>
Thu, 10 Dec 2020 11:12:10 +0000 (06:12 -0500)
committerHypolite Petovan <hypolite@mrpetovan.com>
Thu, 10 Dec 2020 11:12:10 +0000 (06:12 -0500)
- Address https://github.com/friendica/friendica/issues/9250#issuecomment-741857058

src/Database/Database.php
src/Model/Item.php

index 641ebd3894dc1fa4f68a3d9996b38918696079be..0d02c4aef4251438ab7879e19454456ebfb11bce 100644 (file)
@@ -910,13 +910,12 @@ class Database
        /**
         * Fetch a single row
         *
-        * @param mixed $stmt statement object
+        * @param PDOStatement|mysqli_stmt $stmt statement object
         *
-        * @return array current row
+        * @return array|false current row
         */
        public function fetch($stmt)
        {
-
                $stamp1 = microtime(true);
 
                $columns = [];
@@ -934,7 +933,7 @@ class Database
                                break;
                        case self::MYSQLI:
                                if (get_class($stmt) == 'mysqli_result') {
-                                       $columns = $stmt->fetch_assoc();
+                                       $columns = $stmt->fetch_assoc() ?? false;
                                        break;
                                }
 
index 15ea69eeb94df1a40d0c770698a3aef767a3f4d5..c67399b9289011852c3795c20a0c51f916dcc3d5 100644 (file)
@@ -223,13 +223,14 @@ class Item
         * Fetch a single item row
         *
         * @param mixed $stmt statement object
-        * @return array current row
+        * @return array|false current row or false
+        * @throws \Exception
         */
        public static function fetch($stmt)
        {
                $row = DBA::fetch($stmt);
 
-               if (is_bool($row)) {
+               if (!is_array($row)) {
                        return $row;
                }