<?php
/**
- * @copyright Copyright (C) 2020, Friendica
+ * @copyright Copyright (C) 2010-2021, the Friendica project
*
* @license GNU AGPL version 3 or any later version
*
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])) {
public function p($sql)
{
+ $this->profiler->startRecording('database');
$stamp1 = microtime(true);
$params = DBA::getParam(func_get_args());
// 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;
break;
}
- foreach ($args AS $param => $value) {
+ foreach ($args as $param => $value) {
if (is_int($args[$param])) {
$data_type = PDO::PARAM_INT;
} else {
$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])) {
$this->errorno = $errorno;
}
- $this->profiler->saveTimestamp($stamp1, 'database');
+ $this->profiler->stopRecording();
if ($this->configCache->get('system', 'db_log')) {
$stamp2 = microtime(true);
public function e($sql)
{
- $stamp = microtime(true);
+ $this->profiler->startRecording('database_write');
$params = DBA::getParam(func_get_args());
$this->errorno = $errorno;
}
- $this->profiler->saveTimestamp($stamp, "database_write");
+ $this->profiler->stopRecording();
return $retval;
}
*/
public function fetch($stmt)
{
- $stamp1 = microtime(true);
+ $this->profiler->startRecording('database');
$columns = [];
$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;
}
}
- $this->profiler->saveTimestamp($stamp1, 'database');
+ $this->profiler->stopRecording();
return $columns;
}
* @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
}
}
- 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]);
}
$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'];
+ }
}
/**
public function close($stmt)
{
- $stamp1 = microtime(true);
+ $this->profiler->startRecording('database');
if (!is_object($stmt)) {
return false;
break;
}
- $this->profiler->saveTimestamp($stamp1, 'database');
+ $this->profiler->stopRecording();
return $ret;
}