Jump to content

php print out all mysql queries?


bpops

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?
Link to comment
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.
Link to comment
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!
Link to comment
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.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

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.   Restore formatting

  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.

×
×
  • Create New...

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.