php - How to Display total mysql queries executed specific mysqli class

225

I am using this php class. here it is https://github.com/joshcam/PHP-MySQLi-Database-Class

Could someone tell me how I can get the number of queries that have been run during a trace session. The trace documentation is at the end of the documentation page on github.

144

Answer

Solution:

According to this documentation, each trace is stored in the object as an array seeprint_r ($db->trace); at the end.

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
        )

So you can get the number of queries executed by just doing

$num = count($db->trace);

People are also looking for solutions to the problem: php - Passing row variables to a function in Codeigniter

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.