Forum Moderators: coopster

Message Too Old, No Replies

How long the query took

how to show query took 0.0xx seconds

         

Jaunty Edward

4:35 am on Aug 5, 2005 (gmt 0)

10+ Year Member



Hi,

I know in mysql command prompt it comes autometically but I want to show how long the query took on the web page itself like its shown on many forums.

Any Ideas, any inbuilt function in mySQL or trick.

Thanks in advance.

Bye

Prolific

4:43 am on Aug 5, 2005 (gmt 0)

10+ Year Member



To put it basically, you need to get the time right before you start the query, do the query, get the time right after the query and then figure out the difference.

Here is a PHP example:


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

$time_start = getmicrotime();

mysql_query( "" );

$time_end = getmicrotime();
$time = $time_end - $time_start;

echo "Did nothing in $time seconds";

Jaunty Edward

4:49 am on Aug 5, 2005 (gmt 0)

10+ Year Member



Hi,

Thanks a million, I had the idea but not the code. I thought may be mysql has some inbuilt function as this thing is important in optimizing and checking the load on mysql server.

Thanks Again.
Bye