PDA

View Full Version : sql queries used in a page ?



GregT
October 30th, 2002, 16:23
what is the code to show how many sql queires were made on a php page ? ive been searching for this but cant find it :(

hohoho
October 31st, 2002, 03:17
i don't think this is possible with an function, but it is possible with a variable thet increases its value with every query

GregT
October 31st, 2002, 15:38
Originally posted by hohoho
i don't think this is possible with an function, but it is possible with a variable thet increases its value with every query

i didnt really mean as a built in function, i mean what would the script be to do that ?

ExoWorks
November 2nd, 2002, 06:24
You can first create a class, and then use that class to execute the sql queries.
And store the number of queries executed in a variable.

Use something like :

<?
$db = mysql_connect("localhost","cbs","asad1801");
mysql_select_db("SPECIAL", $db);

class fetch {
var $query;
var $querynum = 0;

function db_fetch($query) {
global $sql_fetch,$querynum;
$sql_query_sent= mysql_query($query);
$sql_fetch = mysql_fetch_array($sql_query_sent);
$querynum++;
return $query;
}

function db_query($query) {
global $sql_query,$querynum;
$sql_query = mysql_query($query);
$querynum++;
return $query;
}
}

$db = new fetch($query);
$query = $db->db_query("SELECT * FROM SPECIAL");
while($fetch = mysql_fetch_array($sql_query)) {
echo "$fetch[name]<br>";
}


$query = $db->db_fetch("SELECT * FROM SPECIAL");
echo "$sql_fetch[id]<br>";

$query = $db->db_fetch("SELECT * FROM current");
echo "$querynum<br>";
?>

<?
// 6322577
?>