From b1ae6b89c2808ee92ed2d5ca397367e865e1b03a Mon Sep 17 00:00:00 2001 From: thinkphp Date: Tue, 9 Aug 2016 16:40:34 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AE=B0=E5=BD=95=E6=95=B0=E6=8D=AE=E5=BA=93?= =?UTF-8?q?=E8=BF=9E=E6=8E=A5=E6=97=B6=E9=97=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/db/Connection.php | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/library/think/db/Connection.php b/library/think/db/Connection.php index 767c0191..784f858a 100644 --- a/library/think/db/Connection.php +++ b/library/think/db/Connection.php @@ -13,7 +13,6 @@ namespace think\db; use PDO; use PDOStatement; -use think\App; use think\Collection; use think\Db; use think\db\exception\BindParamException; @@ -274,9 +273,14 @@ abstract class Connection if (empty($config['dsn'])) { $config['dsn'] = $this->parseDsn($config); } + if ($config['debug']) { + $startTime = microtime(true); + } $this->links[$linkNum] = new PDO($config['dsn'], $config['username'], $config['password'], $params); - // 记录数据库连接信息 - App::$debug && Log::record('[ DB ] CONNECT: ' . $config['dsn'], 'info'); + if ($config['debug']) { + // 记录数据库连接信息 + Log::record('[ DB ] CONNECT:[ UseTime:' . number_format(microtime(true) - $startTime, 6) . 's ] ' . $config['dsn'], 'sql'); + } } catch (\PDOException $e) { if ($autoConnection) { Log::record($e->getMessage(), 'error');