2

我想在 php 脚本中使用 mysql 查询分析器。因此,在我执行任何查询后,它需要显示查询的执行时间。

建议使用此功能的最佳方法还可以共享任何其他脚本,例如查询分析器。

4

1 回答 1

1

前:

您需要在执行查询之前将 设置为profiling1访问分析信息。

mysql_query("SET profiling = 1");

后:

执行完要测试的查询后,您需要执行以下查询。

$a = mysql_query("
     SELECT query_id, SUM(duration) AS duration 
     FROM information_schema.profiling
     GROUP BY query_id ORDER BY query_id DESC LIMIT 1
     ");

//in case you want to loop through more than one profile
while($b = mysql_fetch($a))
{
    echo 'ID: '.$b['query_id'].'<br>Duration: '.$b['duration'].' seconds';
}

欲了解更多信息:http ://dev.mysql.com/doc/refman/5.0/en/profiling-table.html

于 2009-06-11T08:59:07.700 回答