/    Sign up×
Community /Pin to ProfileBookmark

This page has executed XXX querys?

Does anyone know of or, can tell me how to write a script that will output the number of mysql querys the page had executed?

Thanks for the help,

RyanJ

to post a comment
PHP

8 Comments(s)

Copy linkTweet thisAlerts:
@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;

Cheers
Copy linkTweet thisAlerts:
@sciguyryanauthorSep 13.2004 — [i]Originally posted by Hellspire [/i]

[B]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;



Cheers [/B]
[/QUOTE]


Thanks, never thaught of it that way ?

Can you please give me a demo as I have neer used classes in this way.


Thanks for the help,

RyanJ
Copy linkTweet thisAlerts:
@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...

Cheers
Copy linkTweet thisAlerts:
@sciguyryanauthorSep 13.2004 — Ok, PM sent.


Thanks,

RyanJ
Copy linkTweet thisAlerts:
@HellspireSep 13.2004 — It has been sent.. enjoy
Copy linkTweet thisAlerts:
@sciguyryanauthorSep 14.2004 — [i]Originally posted by Hellspire [/i]

[B]It has been sent.. enjoy [/B][/QUOTE]



I will and thanks again!

RyanJ
Copy linkTweet thisAlerts:
@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.
Copy linkTweet thisAlerts:
@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>&lt;?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-&gt;database = $dbname;
$x-&gt;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 &amp; ~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-&gt;connectionlink == 0){
$this-&gt;connectionlink = @mysql_connect($server,$dbusername,$dbpassword);
}
if(!$this-&gt;connectionlink){
$this-&gt;criticalerror('Could not connect to server database.');
return false;
}
$this-&gt;selectdb($this-&gt;database);
}
function selectdb($datebase=''){
$connectioncheck = @mysql_select_db($this-&gt;database,$this-&gt;connectionlink);
if($connectioncheck){
return true;
}else{
$this-&gt;criticalerror('Could not connect to database.');
return false;
}
}
function query($query_string, $query_type = 'mysql_query'){
$query_id = $query_type($query_string, $this-&gt;connectionlink);
$this-&gt;lastquery = $query_string;
if (!$query_id){
$this-&gt;criticalerror('SQL Query: ' . $query_string);
}
$this-&gt;querycount++;
return $query_id;
}
function affectedrows(){
$this-&gt;rows = mysql_affected_rows($this-&gt;connectionlink);
return $this-&gt;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-&gt;connectionlink);
}
function close(){
return mysql_close($this-&gt;connectionlink);
}
function unbufferedquery($querystring){
return $this-&gt;query($querystring, 'mysql_unbuffered_query');
}
function escapestring($string){
return mysql_escape_string($string);
}
function fetch($querystring,$type = DBARRAY_ASSOC){
$query_id = $this-&gt;query($querystring);
$returnarray = $this-&gt;fetcharray($query_id,$type);
$this-&gt;freeresult($query_id);
return $returnarray;
}
function geterrordesc(){
$this-&gt;error = mysql_error($this-&gt;connectionlink);
return $this-&gt;error;
}
function geterrorno(){

<i> </i>$this-&gt;errorno = mysql_errno($this-&gt;connectionlink);
<i> </i>return $this-&gt;errorno;
}
function fetchrow($query_id){
return @mysql_fetch_row($query_id);
}
function criticalerror($message){
// we will do NOTHING!!!!!!!!!
$this-&gt;critical = array($this-&gt;geterrorno(),$this-&gt;geterrordesc,$message,);
return $this-&gt;critical;
}
}
?&gt;


Enjoy.
×

Success!

Help @sciguyryan spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...