Hi
I am looking for a script that will count the number of queries per page and also the query time however the script uses various methods like below to do queries and I don't want to change the several hundred types.
For example:
$result = $dbA->query("select * from $tableLabels");
$fieldList = $dbA->retrieveAllRecordsFromQuery("select * from $tableCustomerFields where type='AF' and visible=1 and internalOnly=0");
$cresult = $dbA->query("select * from $tableAffiliates where affiliateID=".$affiliateMain["affiliateID"]);
$dbA->query("update $tableAffiliates set arID=\"$rID\" where affiliateID=$jssAffiliateLogin");
Therefore is is possible to amend the below code so it can look at $dba as that would work without changing them all. Otherwise is it possible to find something else in common to make it work.
PHP Code:
<?php
//connexion
mysql_connect($host,$username,$password);
mysql_select_db('mydatabase');
//We start the counter at 0
$nb_queries = 0;
//The function to time the execution time
function timer()
{
$time = explode(' ', microtime());
return $time[0]+$time[1];
}
$timer_queries = 0;
//The fonction that count the number of queries and their execution time
function query($query)
{
//We increase the queries counter by 1
global $nb_queries,$timer_queries;
$nb_queries++;
//Execute the query and time the execution time
$beginning = timer();
//Execute the query and save the result in a variable
$req_return = mysql_query($query);
//We add the query duration to the total
$timer_queries += round(timer()-$beginning,6);
return $req_return;
}
//We run some queries for the example
$requete1 = query('select count(username) as nb from users');
$donnee1 = mysql_fetch_array($requete1);
echo "The Data Base contain ".$donnee1['nb']." users.<br />";
$requete1 = query('select username from users');
echo "This is a list of the users:<br />";
while($donnee1 = mysql_fetch_array($requete1))
{
echo "<strong>".$donnee1['username']."</strong><br />";
}
//Show the result
echo $nb_queries.' mysql queries executed in '.$timer_queries.' seconds';
?>
Thanks
Roy