Jump to content

How do I "count" queries in PHP (MySQL)


SNN

Recommended Posts

Just off the top of my head, you could write a function like this:

 

function query_and_count($query) {
   global $count;      
   $count = $count + 1;
   return mysql_query($query);
}

 

Then, at the top of your scripts, add this code:

 

global $count = 0;
$start_time = time();

 

And each time you want to do a query, you just call the code (for example):

 

query_and_count("SELECT * FROM table);

 

And at the end of your script, you use this code:

 

$finish_time = time();
$total_time = $finish_time - $start_time;
$output_time = date("s", $total_time) . "." . date("u", $total_time);
echo "Page generated in " . $output_time . " seconds with " . $count . "queries";

 

disclaimer: non-tested, just written off the top of my head.

Archived

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

×
×
  • Create New...

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.