Jump to content

Archived

This topic is now archived and is closed to further replies.

bpops

php print out all mysql queries?

Recommended Posts

Is there a way to print out ALL mysql queries sent during a php script, without manually typing code to show the queries.

This is a continuation of a previous problem I've been  having where I think mysql is for some reason getting queries that I am not sending it. I want some sort of diagnostic that will print out everything sent via mysql.

Anyone know if theres a setting or something?

Share this post


Link to post
Share on other sites
While I don't know for sure, I learned recently that MySQL caches queries -- or can cache them -- so long as they are preconstructed before they are sent (ie you can't have MySQL create the queries for you).  I'm not sure how to turn this on or how to consult the cache, but I'm sure you can search for and find it.

Share this post


Link to post
Share on other sites
Thanks

I googled this, but it seems as though you can only see the size of the cache and not the cache itself.
Anyone else?

It's frustrating because I only have this single mysql_query, and it is apparently running itself 2-3 times in a single script for no reason at all.
Thanks!

Share this post


Link to post
Share on other sites
Why don't you post some code so we can look for a loop or something?  Also, why do you suspect the query is being run multiple times?

Share this post


Link to post
Share on other sites
Ok, here's my code (changed and rewritten from my last thread about this).
It's a database of items each with its own counter (kind of like phpfreaks has on their tutorials). I use cookies so people can't just hit refresh to increment the counter.

[code]
<?php
//I've cut out here where I've connected to the database, and pulled
//out a single item. it's unique id is $id (auto_increment), and its number
//of hits is $hits

//Counter Cookie
$cc_name = "counter"; // Name of the cookie
$cc_expires = time() + 3600; // Expires in an hour
//Create cookie if it does not already exist
if(!$_COOKIE[$cc_name])
setcookie($cc_name, "", $cc_expires); // Create the cookie

//Set cookie info
$cc_item = "[$id]"; // Item identifier in [XX] format
$cc_value = $_COOKIE[$cc_name];
if (strpos($cc_value, $cc_item) === FALSE) // If the user has not visited this page
{
// Increase view count in database 
$hits++;
mysql_query("UPDATE wow_items SET hits=$hits WHERE id=$id");
$cc_value .= $cc_item; // Add the item to the cookie
}
  setcookie($cc_name, $cc_value, $cc_expires); // Create or re-create the cookie

?>[/code]

Ok, now say the hits was originally 1. When you load the page, it will increment to 2. And if I print out $hits (which I do) on this same page, it prints a 2. So the mysql_query MUST set this to 2. However, if reload the page, it will jump to 3 or 4 (its not even consistent). After this, reloads do not change the value.

I also was wondering if the first reload was doing it. So then I tried going to a page. It increments appropriately (to 2 from 1), then I talk to mysql directly and see that the hits column for this item is now 3 (or 4).

It's so confusing and I've spent hours on this problem. I've had several of my friends look at it, too, and no one can figure out what's wrong.

Thanks if anyone can help.

Share this post


Link to post
Share on other sites
*edit.

removed this post.. forget it, im giving up on this. no one seems to want to help :(

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.