Jump to content
xisto Community
Sign in to follow this  
Amezis

Show Number Of Queries In The Footer

Recommended Posts

Hi, I need a script showing the number of queries done in the footer of my page.If possible, I would also like a script showing how much time the queries took, and the time used to generate the page. But a script showing the number of queries is currently the most important :huh:

Share this post


Link to post
Share on other sites

Uh, in relation to what? There isn't a single script that is going to be universally applicable to absolutely every possible situation. I would suggest you simply keep a record of how many queries are executed in the pre-processing of your page, and how long it took to execute them. It's not that difficult.

Share this post


Link to post
Share on other sites

Create a class in the php file called DB for executing and doing all your database query related work.And for every query you pass into it, it will execute it and at the same time, increment a counter variable.You can use this variable for showing up the amount of queries executed.

Share this post


Link to post
Share on other sites

That's something along the lines of what I was thinking. Here is a very quick, untested, written purely for example demo:

<?phpclass database {   var $_query_count = 0;   var $_conn_id = 0;   var $_query_result = 0;   var $_execution_time = 0;   function database( $db_host, $db_user, $db_pass ) {	  $this->_conn_id = @mysql_pconnect($db_host,$db_user,$db_pass);	  if( !$this->_conn_id ) {		 return false;	  }	  return $this->_conn_id;   }   function sql_query( $query ) {	  $time_start = time() + microtime();	  $this->_query_result = @mysql_query($query);	  $time_end = time()+microtime();	  $this->_query_count++;	  $this->_execution_time += ($time_end-$time_start);   }   function close() {	  @mysql_free_result($this->_query_result);	  @mysql_close($this->_conn_id);   }}?>

Usage could be something along the lines of:

$database = new database('host','user','pass');$database->sql_query('SELECT X FROM Y');echo '[ Time: ' . $database->_execution_time . ' ] [ Queries: ' . $database->_query_count . ' ]';$database->close();

As I said earlier, however, this is not a 'universal' solution. You are going to have to do some coding of your own to integrate it into whatever environment you wish for it to exist. Hope it helps all the same.

Oh, and feel free to use that code as you wish.
Edited by Spectre (see edit history)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | 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.