From cfeaf36b276a7c992c14237bfdb13083a2d82e8c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mr=C2=B7x?= Date: Fri, 5 Mar 2021 15:08:40 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Database/Command.php | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/Database/Command.php b/Database/Command.php index 737901c6..481bad5c 100644 --- a/Database/Command.php +++ b/Database/Command.php @@ -118,37 +118,42 @@ class Command extends Component */ private function execute($type, $isInsert = null, $hasAutoIncrement = null): int|bool|array|string|null { + $time = microtime(true); try { - $time = microtime(true); if ($type === static::EXECUTE) { $result = $this->insert_or_change($isInsert, $hasAutoIncrement); } else { $result = $this->search($type); } - $this->setExecuteLog($time); if ($this->prepare) { $this->prepare->closeCursor(); } } catch (\Throwable $exception) { - $result = $this->addError($this->sql . '. error: ' . $exception->getMessage(), 'mysql'); + $message = $this->sql . '. error: ' . $exception->getMessage(); + + $result = $this->addError($message, 'mysql'); } finally { - return $result; + return $this->setExecuteLog($time, $result); } } /** * @param $time + * @param $result + * @return mixed * @throws ComponentException * @throws Exception */ - private function setExecuteLog($time) + private function setExecuteLog($time, $result): mixed { $export['sql'] = $this->sql; $export['param'] = $this->params; $export['time'] = microtime(true) - $time; logger()->debug(print_r($export, true), 'mysql'); + + return $result; }