Jump to content


Photo

php print out all mysql queries?


  • Please log in to reply
5 replies to this topic

#1 bpops

bpops
  • Members
  • PipPipPip
  • Advanced Member
  • 232 posts

Posted 01 August 2006 - 03:51 PM

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?

#2 Buyocat

Buyocat
  • Members
  • PipPipPip
  • Advanced Member
  • 267 posts

Posted 01 August 2006 - 04:02 PM

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.
Looking for some easy-to-use tools?  Try these, https://sourceforge....jects/utils-php -- I made them myself.  They're distinct tools which are easy to understand and use.  See some examples uses at http://www.anotherearlymorning.com

#3 bpops

bpops
  • Members
  • PipPipPip
  • Advanced Member
  • 232 posts

Posted 01 August 2006 - 04:09 PM

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!

#4 Buyocat

Buyocat
  • Members
  • PipPipPip
  • Advanced Member
  • 267 posts

Posted 01 August 2006 - 04:15 PM

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?
Looking for some easy-to-use tools?  Try these, https://sourceforge....jects/utils-php -- I made them myself.  They're distinct tools which are easy to understand and use.  See some examples uses at http://www.anotherearlymorning.com

#5 bpops

bpops
  • Members
  • PipPipPip
  • Advanced Member
  • 232 posts

Posted 01 August 2006 - 04:28 PM

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.

<?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

?>

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.

#6 bpops

bpops
  • Members
  • PipPipPip
  • Advanced Member
  • 232 posts

Posted 01 August 2006 - 04:43 PM

*edit.

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




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users