查找MySql查询运行时


Find MySql query run time?

有没有一种简单的方法可以找到并显示上一个MySQL查询执行的时间?我在想一个PHP中的系统函数或类似函数。到目前为止,我想出的最好的方法是用微时间生成两个变量,其中一个在查询之前,另一个在之后。其中最后一个是第一个的子字符串($querytime=$after-$before)。

最终结果旨在显示您在PhpMyAdmin和类似程序中找到的内容,即"您的查询在xxxx.xx秒内完成"。

$start_time = microtime(true);
mysql_query("SELECT * FROM something");
$end_time = microtime(true);
$total_time = $end_time – $start_time;
//there isn't faster way