Mysql Queries

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
DeGauss
Forum Contributor
Posts: 105
Joined: Tue Oct 22, 2002 9:44 am
Location: Gainesville, FL

Mysql Queries

Post 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.
User avatar
d1223m
Forum Commoner
Posts: 80
Joined: Mon Mar 31, 2003 5:15 am
Location: UK, West Sussex

Post 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
DeGauss
Forum Contributor
Posts: 105
Joined: Tue Oct 22, 2002 9:44 am
Location: Gainesville, FL

Post 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.
User avatar
d1223m
Forum Commoner
Posts: 80
Joined: Mon Mar 31, 2003 5:15 am
Location: UK, West Sussex

Post by d1223m »

most of those ive seen dont show mysql times just the total page time
McGruff
DevNet Master
Posts: 2893
Joined: Thu Jan 30, 2003 8:26 pm
Location: Glasgow, Scotland

Post 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);
?>
Last edited by McGruff on Thu Aug 11, 2005 12:03 pm, edited 1 time in total.
McGruff
DevNet Master
Posts: 2893
Joined: Thu Jan 30, 2003 8:26 pm
Location: Glasgow, Scotland

Post 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
bionicdonkey
Forum Contributor
Posts: 132
Joined: Fri Jan 31, 2003 2:28 am
Location: Sydney, Australia
Contact:

Post by bionicdonkey »

have u tried mysql_info???
Post Reply