@HellspireSep 13.2004 — #I use mysql as a class (and i believe this is the only way to track it without having to add a counter after each query on every page (ugh...)
so every time query() is called in my class it does $this->querycount++
and at the end of my page i simply have to call it into a normal var or output it as echo $this->querycount;
@HellspireSep 13.2004 — #PM me your email address and I will give you a working class that I completed a while ago... I'm between classes right now and everything is at home on my comp...
@Stephen_PhilbinSep 14.2004 — #How about posting it? For a long time I've failed to see any point at all in php classes so I wouldn't mind getting some ideas.
@HellspireSep 14.2004 — #Good idea. Note that classes are a way for shortening code tremendously.... also for tracking things as forementioned querycount, and a management of critical errors (although I didn't include my version of critical error management, or the more advanced functions in this public release. (Cant give away everything ?)
<i> </i><?php # Created by Matthew Shockley (Hellspire) # Riftwarp Systems, redistributed by request... # [email][email protected][/email] /* i have those vars set in a config file, you dont have to stick to $x obviouosly...
$x = new sql; $x->database = $dbname; $x->connect($dbserver,$dbusern,$dbpassn); unset($dbname,$dbserver,$dbusern,$dbpassn); // this must be declared AFTER the class has been included.....
the functions should be fairly obvious... more advanced features are available in the full release enjoy... Please note that this version is BETA, as i will not release the full one ^_~ */ error_reporting(E_ALL & ~E_NOTICE); define('DBARRAY_NUM', MYSQL_NUM); define('DBARRAY_ASSOC', MYSQL_ASSOC); define('DBARRAY_BOTH', MYSQL_BOTH);
class sql { var $connectionlink = 0; var $database = ''; var $errordesc = ''; var $errorno = 0; var $reporterror = 0; var $querycount = 0; var $critical = '';
function connect($server,$dbusername,$dbpassword){ if($this->connectionlink == 0){ $this->connectionlink = @mysql_connect($server,$dbusername,$dbpassword); } if(!$this->connectionlink){ $this->criticalerror('Could not connect to server database.'); return false; } $this->selectdb($this->database); } function selectdb($datebase=''){ $connectioncheck = @mysql_select_db($this->database,$this->connectionlink); if($connectioncheck){ return true; }else{ $this->criticalerror('Could not connect to database.'); return false; } } function query($query_string, $query_type = 'mysql_query'){ $query_id = $query_type($query_string, $this->connectionlink); $this->lastquery = $query_string; if (!$query_id){ $this->criticalerror('SQL Query: ' . $query_string); } $this->querycount++; return $query_id; } function affectedrows(){ $this->rows = mysql_affected_rows($this->connectionlink); return $this->rows; } function fetcharray($query_id,$type = DBARRAY_ASSOC){ return @mysql_fetch_array($query_id,$type); } function freeresult($query_id){ return @mysql_free_result($query_id); } function dataseek($position,$query_id){ return @mysql_data_seek($query_id,$position); } function numrows($query_id){ return mysql_num_rows($query_id); } function numfields($query_id){ return mysql_num_fields($query_id); } function fieldname($query_id,$columnnum){ return mysql_field_name($query_id, $columnnum); } function insertid(){ return mysql_insert_id($this->connectionlink); } function close(){ return mysql_close($this->connectionlink); } function unbufferedquery($querystring){ return $this->query($querystring, 'mysql_unbuffered_query'); } function escapestring($string){ return mysql_escape_string($string); } function fetch($querystring,$type = DBARRAY_ASSOC){ $query_id = $this->query($querystring); $returnarray = $this->fetcharray($query_id,$type); $this->freeresult($query_id); return $returnarray; } function geterrordesc(){ $this->error = mysql_error($this->connectionlink); return $this->error; } function geterrorno(){
<i> </i>$this->errorno = mysql_errno($this->connectionlink); <i> </i>return $this->errorno; } function fetchrow($query_id){ return @mysql_fetch_row($query_id); } function criticalerror($message){ // we will do NOTHING!!!!!!!!! $this->critical = array($this->geterrorno(),$this->geterrordesc,$message,); return $this->critical; } } ?>