From e7fa5eb38ae39936e5c08ab3fa486d64579150d2 Mon Sep 17 00:00:00 2001 From: slawkens Date: Thu, 26 Mar 2020 02:03:32 +0100 Subject: [PATCH] Log query time in database_log --- system/libs/pot/OTS_Base_DB.php | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/system/libs/pot/OTS_Base_DB.php b/system/libs/pot/OTS_Base_DB.php index cf04a5e3..9e34ba11 100644 --- a/system/libs/pot/OTS_Base_DB.php +++ b/system/libs/pot/OTS_Base_DB.php @@ -74,15 +74,21 @@ abstract class OTS_Base_DB extends PDO implements IOTS_DB return $this->fieldName($this->prefix . $name); } - public function query($query) - { + public function query($query) + { + $this->queries++; + if($this->logged) { - $this->log .= $query . PHP_EOL; + $startTime = microtime(true); } - $this->queries++; - //echo $query . PHP_EOL; - return parent::query($query); + $ret = parent::query($query); + if($this->logged) { + $totalTime = microtime(true) - $startTime; + $this->log .= round($totalTime, 4) . ' ms - ' . $query . PHP_EOL; + } + + return $ret; } public function select($table, $data)