]> git.mxchange.org Git - friendica.git/blobdiff - src/Database/Database.php
Code Style: Replace "AS" with "as"
[friendica.git] / src / Database / Database.php
index 5b488e11f1543e18b80d9071f14e908a2716afa6..f94e03f92a8b48e95ada041c7a68a6ebffc95018 100644 (file)
@@ -434,7 +434,7 @@ class Database
        private function replaceParameters($sql, $args)
        {
                $offset = 0;
-               foreach ($args AS $param => $value) {
+               foreach ($args as $param => $value) {
                        if (is_int($args[$param]) || is_float($args[$param]) || is_bool($args[$param])) {
                                $replace = intval($args[$param]);
                        } elseif (is_null($args[$param])) {
@@ -476,7 +476,7 @@ class Database
                // Renumber the array keys to be sure that they fit
                $i    = 0;
                $args = [];
-               foreach ($params AS $param) {
+               foreach ($params as $param) {
                        // Avoid problems with some MySQL servers and boolean values. See issue #3645
                        if (is_bool($param)) {
                                $param = (int)$param;
@@ -549,7 +549,7 @@ class Database
                                        break;
                                }
 
-                               foreach ($args AS $param => $value) {
+                               foreach ($args as $param => $value) {
                                        if (is_int($args[$param])) {
                                                $data_type = PDO::PARAM_INT;
                                        } else {
@@ -605,7 +605,7 @@ class Database
 
                                $param_types = '';
                                $values      = [];
-                               foreach ($args AS $param => $value) {
+                               foreach ($args as $param => $value) {
                                        if (is_int($args[$param])) {
                                                $param_types .= 'i';
                                        } elseif (is_float($args[$param])) {
@@ -958,7 +958,7 @@ class Database
                                $result = $stmt->result_metadata();
                                $fields = $result->fetch_fields();
 
-                               foreach ($cols_num AS $param => $col) {
+                               foreach ($cols_num as $param => $col) {
                                        $columns[$fields[$param]->name] = $col;
                                }
                }
@@ -1267,7 +1267,7 @@ class Database
         * @param string|array  $table      Table name or array [schema => table]
         * @param array         $fields     contains the fields that are updated
         * @param array         $condition  condition array with the key values
-        * @param array|boolean $old_fields array with the old field values that are about to be replaced (true = update on duplicate)
+        * @param array|boolean $old_fields array with the old field values that are about to be replaced (true = update on duplicate, false = don't update identical fields)
         *
         * @return boolean was the update successfull?
         * @throws \Exception
@@ -1293,7 +1293,7 @@ class Database
                        }
                }
 
-               foreach ($old_fields AS $fieldname => $content) {
+               foreach ($old_fields as $fieldname => $content) {
                        if (isset($fields[$fieldname]) && !is_null($content) && ($fields[$fieldname] == $content)) {
                                unset($fields[$fieldname]);
                        }
@@ -1461,8 +1461,12 @@ class Database
 
                $row = $this->fetchFirst($sql, $condition);
 
-               // Ensure to always return either a "null" or a numeric value
-               return is_numeric($row['count']) ? (int)$row['count'] : $row['count'];
+               if (!isset($row['count'])) {
+                       $this->logger->notice('Invalid count.', ['table' => $table, 'row' => $row, 'expression' => $expression, 'condition' => $condition_string, 'callstack' => System::callstack()]);
+                       return 0;
+               } else {
+                       return (int)$row['count'];
+               }
        }
 
        /**