Page 1 of 1

Query counter

Posted: 2021-01-11 15:20
by onoehring
Hi,

I would like to have an easier opportunity to get the count of all dabatase queries from time X to time Y. This would make debugging and optimizing sometimes a lot easier.

My suggestion is to set a session variable as a counter and each time the developer uses the sql() or sqlValue() function the counter is increased. The developer can easily reset the counter i.e. clear it in the footer.

Right now I am adding the line

Code: Select all

$_SESSION['countSQLQueries'] ++;
after each line where I am using sql() or sqlValue() which blows up code - and could be omitted easily.

Olaf

Re: Query counter

Posted: 2021-01-11 17:48
by pfrumkin
Hi Olaf,

I am not following the value of such a counter. Is it that this way you could tell if your code hit that line to do the query? I add lines of code to write to a file which has several downsides. I am fortunate that our site doesn't have a lot of traffic so these log files don't have contention problems.

Could you implement your own versions of the sql and sqlvalue functions that do the session variable update and make then make the actual sql and sqlvalue calls?

~Paul

Re: Query counter

Posted: 2021-01-13 07:17
by onoehring
Hi Paul,
Could you implement your own versions of the sql and sqlvalue functions that do the session variable update and make then make the actual sql and sqlvalue calls?
A good idea. Something like this should probably do

Code: Select all

function sqlC($sql, $eo){
  $result = sql($sql, $eo);
  $_SESSION['countSQLQueries'] ++;
  return $result;
}
and

Code: Select all

function sqlValueC($sql){
  $result = sqlValue($sql);
  $_SESSION['countSQLQueries'] ++;
  return $result;
}
PS: I have pages that have hundreds or even thousands of SQL queries to build them. Optimizing and getting a hand on where/what is an issue ;-)

Olaf