Jump to content


Photo

Show query information


  • Please log in to reply
4 replies to this topic

#1 Brandon Jaeger

Brandon Jaeger
  • Members
  • PipPipPip
  • Advanced Member
  • 155 posts
  • LocationPA
  • Age:25

Posted 23 June 2006 - 12:11 PM

How would I display (1) the number of queries executed and (2) the time it took those queries? I've seen it on some websites before.

Thanks in advance.

---brandon
PHP is my friend (=

#2 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 23 June 2006 - 12:19 PM

The below isn't my code. I saved it from a post here long, long, ago. At worst, it'll give you a starting point:

<?php
$starttime = explode(' ', microtime());
$starttime = (float)$starttime[1] + (float)$starttime[0];

/* code, code, code... */

$status = explode('  ', mysql_stat($link));
$startquery = str_replace('Questions: ', '', $status[2]);
/* query query query... */
$status = explode('  ', mysql_stat($link));
$endquery = str_replace('Questions: ', '', $status[2]);
$totalquery = $endquery - $startquery;

/* code, code, code... */

$endtime = explode(' ', microtime());
$endtime = (float)$endtime[1] + (float)$endtime[0];
$totaltime = number_format(($endtime - $starttime), 4, '.', '');

echo "Page parsed in $totaltime secs.<br>MySQL using $totalquery queries.";
?>

Original post author's note
please note that $link in this example is a link variable from the database connection, so you might have to change it to your link variable to make it work.
Legend has it that reading the manual never killed anyone.
My site

#3 Brandon Jaeger

Brandon Jaeger
  • Members
  • PipPipPip
  • Advanced Member
  • 155 posts
  • LocationPA
  • Age:25

Posted 23 June 2006 - 09:50 PM

I don't get it.

$status = explode('  ', mysql_stat($link));
$startquery = str_replace('Questions: ', '', $status[2]);
/* query query query... */
$status = explode('  ', mysql_stat($link));
$endquery = str_replace('Questions: ', '', $status[2]);
$totalquery = $endquery - $startquery;
What's are these 'Questions: ' and $status[] parts?
PHP is my friend (=

#4 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 23 June 2006 - 09:54 PM

[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]What's are these 'Questions: ' and $status[] parts?[/quote]

Check the php manual for the mysql_stat function and all will become clear.
Legend has it that reading the manual never killed anyone.
My site

#5 Brandon Jaeger

Brandon Jaeger
  • Members
  • PipPipPip
  • Advanced Member
  • 155 posts
  • LocationPA
  • Age:25

Posted 23 June 2006 - 10:02 PM

Oh, I see now! [2] => Questions: 1321299

I didn't realize it was this simple! Thank you, AndyB.

---brandon
PHP is my friend (=




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users