Jump to content
php.lv forumi

Query counter


daGrevis

Recommended Posts

Laba diena,

Ko jūs domājat par šādu metodi pieprasījumu skaitīšanai...

 

$queries = -1; // Set $queries.

// Some code.

//mysql_query();
$queries++;

// Some code.

//mysql_query();
$queries++;

// Some code.

function foo()
{
   global $queries; // Šis man nepatīk! /dG/

   //mysql_query();
   $queries++;

   echo 2 + 2;
}

// Some code.

if($queries > 0) {
   $queries = 0;
}

echo 'Page loaded with ' . $queries . 'queries.';

Edited by daGrevis
Link to comment
Share on other sites

Ja ar kvērijiem tiktu galā kāda OOP klasīte, tad būtu daudz plašākas iespējas...

 

Pie topika "Noderīgas funkcijas" biju iemetis vienu skriptu, kas overraido mysql_query, un tur var redzēt cik kvēriji izpildās un cik ilgi katrs no tiem...

Link to comment
Share on other sites

Man ar šī lieta pašlaik ir aktuāla, bet es vnk izveidoju fju.

 

// def vars
$queries_count = 0;

function query($sql)
{
global $queries_count;
mysql_query($sql);
$queries_count++;
}

// pieprasam kko.
$username = query("SELECT uname FROM table WHERE ID = ID");

echo "Lapā ir ".$queries_count." kvēriji";

Edited by anonīms
Link to comment
Share on other sites

hmm, vnk viņš to noformēja un pasniedza visiem saprotamāk. no tava "foo" sazin ko var padomāt... :D:D:D

 

Mle, kas tev pret foo??! :D :D :D

 

Mana versija.

$queries = 0;

$queries++;

echo $queries;

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...