diff options
| author | Michael Foster <savetheinternet@tinyboard.org> | 2013-08-30 08:39:11 +1000 |
|---|---|---|
| committer | Michael Foster <savetheinternet@tinyboard.org> | 2013-08-30 08:39:11 +1000 |
| commit | 343803afb9de3b27ba44d9594b6770f9c84d2e54 (patch) | |
| tree | 95e429f5ab6875f5ce41e54702ff94aa357d5d9b /inc/database.php | |
| parent | 8921eb9c1a43e13e096fe72850d75dcf2974483f (diff) | |
More $config['debug'] improvements to time-related stuff
Diffstat (limited to 'inc/database.php')
| -rw-r--r-- | inc/database.php | 21 |
1 files changed, 15 insertions, 6 deletions
diff --git a/inc/database.php b/inc/database.php index 8daa20b4..55e1ff81 100644 --- a/inc/database.php +++ b/inc/database.php @@ -28,13 +28,13 @@ class PreparedQueryDebug { $return = call_user_func_array(array($this->query, $function), $args); if ($config['debug'] && $function == 'execute') { - $time = round((microtime(true) - $start) * 1000, 2) . 'ms'; - + $time = microtime(true) - $start; $debug['sql'][] = array( 'query' => $this->query->queryString, 'rows' => $this->query->rowCount(), - 'time' => '~' . $time + 'time' => '~' . round($time * 1000, 2) . 'ms' ); + $debug['time']['db_queries'] += $time; } return $return; @@ -42,10 +42,14 @@ class PreparedQueryDebug { } function sql_open() { - global $pdo, $config; + global $pdo, $config, $debug; if ($pdo) return true; + + if ($config['debug']) + $start = microtime(true); + if (isset($config['db']['server'][0]) && $config['db']['server'][0] == ':') $unix_socket = substr($config['db']['server'], 1); else @@ -64,6 +68,10 @@ function sql_open() { if ($config['db']['persistent']) $options[PDO::ATTR_PERSISTENT] = true; $pdo = new PDO($dsn, $config['db']['user'], $config['db']['password'], $options); + + if ($config['debug']) + $debug['time']['db_connect'] = '~' . round((microtime(true) - $start) * 1000, 2) . 'ms'; + if (mysql_version() >= 50503) query('SET NAMES utf8mb4') or error(db_error()); else @@ -117,12 +125,13 @@ function query($query) { $query = $pdo->query($query); if (!$query) return false; - $time = round((microtime(true) - $start) * 1000, 2) . 'ms'; + $time = microtime(true) - $start; $debug['sql'][] = array( 'query' => $query->queryString, 'rows' => $query->rowCount(), - 'time' => '~' . $time + 'time' => '~' . round($time * 1000, 2) . 'ms' ); + $debug['time']['db_queries'] += $time; return $query; } |
