0

我正在使用这个 php 类。这里是https://github.com/joshcam/PHP-MySQLi-Database-Class

有人可以告诉我如何获取在跟踪会话期间运行的查询数量。跟踪文档位于 github 上文档页面的末尾。

4

1 回答 1

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);
于 2015-12-10T09:15:20.777 回答