]> git.mxchange.org Git - friendica.git/commitdiff
New function to calculate rows
authorMichael <heluecht@pirati.ca>
Mon, 24 Apr 2017 20:32:35 +0000 (20:32 +0000)
committerMichael <heluecht@pirati.ca>
Mon, 24 Apr 2017 20:32:35 +0000 (20:32 +0000)
include/dba.php

index 4f931e0202fa96f4f66764d973452a0fe0235427..c8c9ecc60d43e7c9e15f8f607c7feb90191b3440 100644 (file)
@@ -587,6 +587,7 @@ class dba {
                                        // Is mysqlnd installed?
                                        $retval = $stmt->get_result();
                                } else {
+                                       $stmt->store_result();
                                        $retval = $stmt;
                                }
                                break;
@@ -676,7 +677,7 @@ class dba {
                if (is_bool($stmt)) {
                        $retval = $stmt;
                } else {
-                       $retval = is_array(self::fetch($stmt));
+                       $retval = (self::rows($stmt) > 0);
                }
 
                self::close($stmt);
@@ -684,6 +685,24 @@ class dba {
                return $retval;
        }
 
+       /**
+        * @brief Returnr the number of rows of a statement
+        *
+        * @param object Statement object
+        * @return int Number of rows
+        */
+       static public function rows($stmt) {
+               switch (self::$dbo->driver) {
+                       case 'pdo':
+                               return $stmt->rowCount();
+                       case 'mysqli':
+                               return $stmt->num_rows;
+                       case 'mysql':
+                               return mysql_num_rows($stmt);
+               }
+               return 0;
+       }
+
        /**
         * @brief Fetch a single row
         *
@@ -726,11 +745,11 @@ class dba {
                                // We need to get the field names for the array keys
                                // It seems that there is no better way to do this.
                                $result = $stmt->result_metadata();
+                               $fields = $result->fetch_fields();
 
                                $columns = array();
-                               foreach ($cols_num AS $col) {
-                                       $field = $result->fetch_field();
-                                       $columns[$field->name] = $col;
+                               foreach ($cols_num AS $param => $col) {
+                                       $columns[$fields[$param]->name] = $col;
                                }
                                return $columns;
                        case 'mysql':