Sql query counter

Simple php script to be able to count how many SQL queries your script does.

$query_counter = 0;//counter for all the executed querys
	function app_query($query) {
	      global $query_counter;
	      $query_counter++;
	      return mysql_query( $query);//later this could be changed for another engine not only mysql
	}

To use it in your script instead of calling the function “mysql_query” , we will use ” app_query”.

To retrieve how many queries were done just:

echo $query_counter;

More simple impossible ;)

Share and Enjoy:
  • Twitter
  • Facebook
  • Digg
  • del.icio.us
  • Google Bookmarks
  • BarraPunto
  • Bitacoras.com
  • FriendFeed
  • Meneame
  • Netvibes
  • Reddit
  • StumbleUpon
  • Tumblr
  • Wikio
  • RSS
  • email
  • PDF
  • Print

Related posts:

  1. Improve your SQL queries
  2. Input select generated from query – PHP
  3. Error reporting for PHP
  4. Simple pagination for PHP
  5. phpMyDB – Data base class for MySql

One Comment

  1. [...] day we show how to count your Sql queries on PHP. Today we do 1 step more in your app to know how long does it takes to be executed in the server [...]

Leave a Reply

Follow me