记录数据库连接时间

This commit is contained in:
thinkphp
2016-08-09 16:40:34 +08:00
parent 285eb470f1
commit b1ae6b89c2

View File

@@ -13,7 +13,6 @@ namespace think\db;
use PDO; use PDO;
use PDOStatement; use PDOStatement;
use think\App;
use think\Collection; use think\Collection;
use think\Db; use think\Db;
use think\db\exception\BindParamException; use think\db\exception\BindParamException;
@@ -274,9 +273,14 @@ abstract class Connection
if (empty($config['dsn'])) { if (empty($config['dsn'])) {
$config['dsn'] = $this->parseDsn($config); $config['dsn'] = $this->parseDsn($config);
} }
if ($config['debug']) {
$startTime = microtime(true);
}
$this->links[$linkNum] = new PDO($config['dsn'], $config['username'], $config['password'], $params); $this->links[$linkNum] = new PDO($config['dsn'], $config['username'], $config['password'], $params);
// 记录数据库连接信息 if ($config['debug']) {
App::$debug && Log::record('[ DB ] CONNECT: ' . $config['dsn'], 'info'); // 记录数据库连接信息
Log::record('[ DB ] CONNECT:[ UseTime:' . number_format(microtime(true) - $startTime, 6) . 's ] ' . $config['dsn'], 'sql');
}
} catch (\PDOException $e) { } catch (\PDOException $e) {
if ($autoConnection) { if ($autoConnection) {
Log::record($e->getMessage(), 'error'); Log::record($e->getMessage(), 'error');