Jump to content

Archived

This topic is now archived and is closed to further replies.

flyhoney

Getting the time a mySQL query took

Recommended Posts

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?



Share this post


Link to post
Share on other sites
As far as i remember Mysql doesnt provide you this data, but you can calculate it like this...

[code]
       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;

[/code]

Share this post


Link to post
Share on other sites
I used the code you posted and it works great. I really appreciate it, makes my search even snazzier.

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.