Page 1 of 1

Mysql Queries

Posted: Mon Apr 07, 2003 9:10 am
by DeGauss
Hey.

Anyone got a bit of code that returns the amount of mysql queries and total execution time in a given script?

I'm trying to not have to rely on mysql_stat, because my version of PHP doesn't support it.

Thanks.

Posted: Mon Apr 07, 2003 9:16 am
by d1223m
surely to that you'd need to time every mysql_query command?

you could make your own:

Code: Select all

function my_mysql_query($qry,$con=false) {
  $starttime=time();
  $result=mysql_query($qry,$con);
  $endtime=time();
  $GLOBALSї'mysql_time']+=$endtime-$starttime;
  return $result;
}
youd want to user higher precision timers but i hope you get the idea i cant think of any other way to do what you want

Posted: Mon Apr 07, 2003 9:25 am
by DeGauss
Hmm... You normally see the kind of thing like this at the end of scripts like PHP Nuke and Invision Board... There has to be an easier way rather than just timing each query.

Bah.

Back to searching.

Posted: Mon Apr 07, 2003 10:12 am
by d1223m
most of those ive seen dont show mysql times just the total page time

Posted: Mon Apr 07, 2003 1:59 pm
by McGruff

Code: Select all

function my_mysql_query($qry,$con=false) {
  $starttime=time();
  $result=mysql_query($qry,$con);
  $endtime=time();
  $GLOBALSї'mysql_time']+=$endtime-$starttime;
  return $result;
}
Or:

Code: Select all

<?php
function getmicrotime(){
    list($usec, $sec) = explode(" ",microtime());
    return ((float)$usec + (float)$sec);
}

$start = getmicrotime();

.. stuff to time

$end = getmicrotime();
$time = $end - $start;
echo "<p>time = " . round($time, 4);
?>

Posted: Mon Apr 07, 2003 2:00 pm
by McGruff
d1223m wrote:most of those ive seen dont show mysql times just the total page time
Mysql Control Centre will show query times - download from mysql.com

Posted: Mon Apr 07, 2003 5:20 pm
by bionicdonkey
have u tried mysql_info???