Processing time and queries used

A

Anonymous

Guest
Hi

I was wondering how the programmers show the query time(how long the server took to complete the query.)

Is there some set of variables or functions that displays how long the last query took and also shows how large a certain database is etc. MYSQL

Pulse :sad:
 
Just get the time before the query, and then after, then subtract the difference.
Code:
<?php
   $M_Conn=mysql_connect ("localhost","username","password");

   mysql_select_db ("Db_name",$M_Conn);

   $SQL="SQL here";
   
   //Get a timestamp
   $PrevTime=time();

   //query
   mysql_query ($SQL,$M_Conn);

   //Get calculate time it took to do the query
   $QueryTime=time() - $PrevTime;

   echo "It took ". $QueryTime ". to query the database with the SQL ". $SQL .".";
?>
 
That's fine and dandy but a timestamp is in seconds where as most querys last milliseconds.

A good article on this can be found here http://www.phpbuilder.com/columns/akent20000926.php3

Some code may need to be updated.. the tutorial is over 3 years old
 
Good point, redcircle.
Okay, replace time() with microtime(). Gives it in microseconds.
 
Back
Top