I'd suggest either;
Using a class and increment a private property:
PHP Code:
<?php
class Query
{
/**
* Number of queries counted
* thus far
*/
private $count = 0;
/**
* Constructor
*
* @return void
*/
public function __construct() {}
/**
* Execute Db query and
* increment counter
*
* @param string $query
* @param resource $link_identifier
* @return resource
*/
public function query($query, $link_identifer = NULL)
{
$this->incrementCounter();
return is_null($link_identifier) ? mysql_query($query) : mysql_query($query, $link_identifier);
}
/**
* Increment Query Counter
*
* @return void
*/
private function incrementCounter()
{
$this->count++;
}
/**
* Get Query Count
*
* @return int
*/
public function getCount()
{
return $this->count;
}
}
/**
* BRIEF EXPLANATION OF USE
*/
$query = new Query;
$result = $query->query('CALL ALL OF YOUR QUERIES LIKE THIS');
echo 'Num of queries: ' . $query->getCount();
Or using and incrementing a static variable within the function scope:
PHP Code:
function query($query, $link_identifer = NULL, $return_count = false)
{
static $count;
if ($return_count)
{
return $count;
}
$count++;
return is_null($link_identifier) ? mysql_query($query) : mysql_query($query, $link_identifier);
}
/**
* BRIEF EXPLANATION OF USE
*/
$result = query('CALL ALL OF YOUR QUERIES LIKE THIS');
echo 'Num of queries: ' . query(0, 0, true);
Bookmarks