Jump to content


Photo

Getting the time a mySQL query took


  • Please log in to reply
2 replies to this topic

#1 flyhoney

flyhoney
  • Members
  • PipPipPip
  • Advanced Member
  • 846 posts
  • LocationAustin, TX

Posted 01 June 2006 - 06:44 AM

I am writing a search function for a website I have been building. I wanted to display the amoun of time a specific query took on the search page. Ive seen this done on other websites, is there a way to do this with mySQL?




"The enemy's gate is down." - Ender
error_reporting(E_ALL);          // place these two lines at the top of 
ini_set('display_errors', 1);    // the script you are debugging

#2 samshel

samshel
  • Members
  • PipPipPip
  • Advanced Member
  • 837 posts

Posted 01 June 2006 - 08:28 AM

As far as i remember Mysql doesnt provide you this data, but you can calculate it like this...

       list($usec, $sec) = explode(' ',microtime());
        $querytime_before = ((float)$usec + (float)$sec);

        $result   = mysql_query($query);

        list($usec, $sec) = explode(' ',microtime());
        $querytime_after = ((float)$usec + (float)$sec);

        $time_taken = $querytime_after - $querytime_before;


Cheers,
SamShel
-----------------------------------------------
--: FUTURE IS LINUX :--
-----------------------------------------------

#3 flyhoney

flyhoney
  • Members
  • PipPipPip
  • Advanced Member
  • 846 posts
  • LocationAustin, TX

Posted 01 June 2006 - 11:59 PM

I used the code you posted and it works great. I really appreciate it, makes my search even snazzier.
"The enemy's gate is down." - Ender
error_reporting(E_ALL);          // place these two lines at the top of 
ini_set('display_errors', 1);    // the script you are debugging




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users