Amezis 0 Report post Posted February 19, 2006 Hi, I need a script showing the number of queries done in the footer of my page.If possible, I would also like a script showing how much time the queries took, and the time used to generate the page. But a script showing the number of queries is currently the most important Share this post Link to post Share on other sites
Spectre 0 Report post Posted February 19, 2006 Uh, in relation to what? There isn't a single script that is going to be universally applicable to absolutely every possible situation. I would suggest you simply keep a record of how many queries are executed in the pre-processing of your page, and how long it took to execute them. It's not that difficult. Share this post Link to post Share on other sites
Amezis 0 Report post Posted February 19, 2006 Basically, this is what I want: Share this post Link to post Share on other sites
OpaQue 15 Report post Posted February 20, 2006 Create a class in the php file called DB for executing and doing all your database query related work.And for every query you pass into it, it will execute it and at the same time, increment a counter variable.You can use this variable for showing up the amount of queries executed. Share this post Link to post Share on other sites
Spectre 0 Report post Posted February 20, 2006 (edited) That's something along the lines of what I was thinking. Here is a very quick, untested, written purely for example demo: <?phpclass database { var $_query_count = 0; var $_conn_id = 0; var $_query_result = 0; var $_execution_time = 0; function database( $db_host, $db_user, $db_pass ) { $this->_conn_id = @mysql_pconnect($db_host,$db_user,$db_pass); if( !$this->_conn_id ) { return false; } return $this->_conn_id; } function sql_query( $query ) { $time_start = time() + microtime(); $this->_query_result = @mysql_query($query); $time_end = time()+microtime(); $this->_query_count++; $this->_execution_time += ($time_end-$time_start); } function close() { @mysql_free_result($this->_query_result); @mysql_close($this->_conn_id); }}?> Usage could be something along the lines of:$database = new database('host','user','pass');$database->sql_query('SELECT X FROM Y');echo '[ Time: ' . $database->_execution_time . ' ] [ Queries: ' . $database->_query_count . ' ]';$database->close(); As I said earlier, however, this is not a 'universal' solution. You are going to have to do some coding of your own to integrate it into whatever environment you wish for it to exist. Hope it helps all the same.Oh, and feel free to use that code as you wish. Edited February 20, 2006 by Spectre (see edit history) Share this post Link to post Share on other sites