Answer the question
In order to leave comments, you need to log in
How to count the number of requests to the database?
Hello.
Interested in the optimal solution for counting the number of queries to the database.
it is possible on the example of mysql, mysqli, PDO.
What I want:
to display in the footer: "Number of requests: 5".
What I came up with:
create a $zapros variable
After each $zapros++ request
In the footer echo $zapros
Disadvantage:
1. one fine moment I forget to write a variable and the request will not be correct.
2. code duplication is bad!
Answer the question
In order to leave comments, you need to log in
Considering that the figure is completely meaningless, it would be easiest to doecho rand(10, 15);
Instead of using mysqli in your code right away, make yourself some kind of wrapper library for these functions and call it.
As part of this library, already collect statistics, log slow queries, etc.
something like this
$sql_count = 0;
function mysql_myquery( $sql = "" )
{
global $sql_count;
++$sql_count;
return mysql_query($sql);
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question