That's something along the lines of what I was thinking. Here is a very quick, untested, written purely for example demo:
CODE
<?php
class 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:
CODE
$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.
Reply