]> git.mxchange.org Git - friendica.git/commitdiff
Correct dba::close() To Match dba::p()
authormiqrogroove <miqrogroove@gmail.com>
Thu, 21 Jun 2018 21:27:12 +0000 (17:27 -0400)
committerGitHub <noreply@github.com>
Thu, 21 Jun 2018 21:27:12 +0000 (17:27 -0400)
include/dba.php

index 478a1a10c2d40e673298121290f26676e3878321..5c9b724340466a3cdc7ce412d93a26fd989a8c04 100644 (file)
@@ -349,7 +349,7 @@ class dba {
         * For all regular queries please use dba::select or dba::exists
         *
         * @param string $sql SQL statement
-        * @return bool|object statement object
+        * @return bool|object statement object or result object
         */
        public static function p($sql) {
                $a = get_app();
@@ -1404,8 +1404,18 @@ class dba {
                                $ret = $stmt->closeCursor();
                                break;
                        case 'mysqli':
-                               $stmt->free_result();
-                               $ret = $stmt->close();
+                               // MySQLi offers both a mysqli_stmt and a mysqli_result class.
+                               // We should be careful not to assume the object type of $stmt
+                               // because dba::p() has been able to return both types.
+                               if ($stmt instanceof mysqli_stmt) {
+                                       $stmt->free_result();
+                                       $ret = $stmt->close();
+                               } elseif ($stmt instanceof mysqli_result) {
+                                       $stmt->free();
+                                       $ret = true;
+                               } else {
+                                       $ret = false;
+                               }
                                break;
                }