function db_query($sql) {
// Declare as static variable before declare global
static $total_mysql_queries;
// Declare as global variable
global $total_mysql_queries;
if(mysql_query($sql)) { // Query successfully executed?
// Add +1 to variable $total_mysql_queries
++$total_mysql_queries;
// Return true, the query was successfully executed
return true;
}
// I'm sure there was a mysql error...
return false;
}
Include the db_query() function into your code, replacing all instances of mysql_query and perform your MySQL queries.
db_query('SELECT `user` FROM `users` WHERE `id` = 1 ORDER BY `id` LIMIT 1;') or die(mysql_error());
db_query('SELECT `user` FROM `users` WHERE `id` = 2 ORDER BY `id` LIMIT 1;') or die(mysql_error());
db_query('SELECT `user` FROM `users` WHERE `id` = 3 ORDER BY `id` LIMIT 1;') or die(mysql_error());
Than, at the end of your code, add:
echo 'A total of ', isset($total_mysql_queries) ? $total_mysql_queries : 0, ' MySQL queries were executed.';