2

I'm testing performance on a CMS I'm making, and I'm wondering is it possible to view what queries were ran on a page load. For example, let's say I run 'test.php'. When I go to it, a list of queries ran by mySQL show at the bottom of the page - is this possible? I've seen sites do this before.

Thanks

Matthew
  • 93
  • 2
  • 6
  • 1
    Possible duplicate => http://stackoverflow.com/questions/1290867/count-number-of-mysql-queries-executed-on-page – user962026 Oct 14 '12 at 01:41

2 Answers2

2

The function SHOW FULL PROCESSLIST will show the real-time and past history of all processes.

SHOW FULL PROCESSLIST

If you are using a server on which you have the rights to install packages, you can install mysqltop and test in real time file and MySQL resource usage and queries.

Ben Lynch
  • 189
  • 2
  • 2
  • 12
Marin Sagovac
  • 3,932
  • 5
  • 23
  • 53
0

Well, if all your queries go through a function then it should be easy, but if each only uses the standard call, then it won't be. This also let's you switch to a different database type or something like that easily.

For instance on the CMS's I modified to be a library program, I have a DB Query function:

function db_query($qstring, $conn) {
$dbh = mysql_db_query($dbname,$qstring, $conn);
// this is where I would add some incrementing code, but it has to be global.
// or just do something like 
if($_GET["debug"]=="debuginSQLcount"){    
    echo $qstring
}
return $dbh;
}

then to use it, I just do something like

$sql = "SELECT stuff";
}
$result = db_query($sql, $link);
if (!$result || db_numrows($result) < 1) {

If you do it like this, then just add a line to the function which increments a $GLOBALS variable or something like that. Read more at PHP global or $GLOBALS

Community
  • 1
  • 1
Karl Henselin
  • 1,015
  • 12
  • 17