我正在使用这个php类。这是https://github.com/joshcam/PHP-MySQLi-Database-Class
有人可以告诉我如何获取在跟踪会话期间运行的查询数量。跟踪文档位于github文档页面的末尾。
答案 0 :(得分:2)
根据此文档,每个跟踪都作为数组存储在对象中,最后请参见print_r ($db->trace);
。
Query exectution time benchmarking
To track query execution time setTrace() function should be called.
$db->setTrace (true);
// As a second parameter it is possible to define prefix of the path which should be striped from filename
// $db->setTrace (true, $_SERVER['SERVER_ROOT']);
$db->get("users");
$db->get("test");
print_r ($db->trace);
[0] => Array
(
[0] => SELECT * FROM t_users ORDER BY `id` ASC
[1] => 0.0010669231414795
[2] => MysqliDb->get() >> file "/avb/work/PHP-MySQLi-Database-Class/tests.php" line #151
)
[1] => Array
(
[0] => SELECT * FROM t_test
[1] => 0.00069189071655273
[2] => MysqliDb->get() >> file "/avb/work/PHP-MySQLi-Database-Class/tests.php" line #152
)
因此,您只需执行
即可获得执行的查询数量$num = count($db->trace);