freelanceprogrammers.org Forum Index » PHP

Debug method suggestion


View user's profile Post To page top
JBennett@... Posted: Thu Jan 12, 2006 11:48 pm


Joined: 08 Apr 2005

Posts: 10
Debug method suggestion
I have built an application that generates much of its SQL on demand and
I wanted to track the queries that were being generated. At first I was
writing the SQL to html comments that I could see using view source, but
at least in Firefox view source seems to call the page again so I lose
the specific SQL that generated the initial page. So here`s my solution:

Whenever I make a database call, the abstraction layer outputs the SQL
inside a div like this:

echo "<div id="hidesql" style="display:none;">$query</div>";

Then I have two links on my page like these:

<a href="javascript:(function(){var
divs=document.getElementsByTagName(`div`);
for(i=0;i<divs.length;i++)if(divs[i].id==`hidesql`)
divs[i].style.display=``;})();">Show SQL</a><br />
<a href="javascript:(function(){var
divs=document.getElementsByTagName(`div`);
for(i=0;i<divs.length;i++)if(divs[i].id==`hidesql`)
divs[i].style.display=`none`;})();">Hide SQL</a><br />

And I`ve also stored them as bookmarklets in case the page fails before
those links render.

Now my SQL comments are invisible until I click the show link. I`ve
also put a couple of other debug comments inside those divs.

Enjoy.

-jmb
Reply with quote
Send private message
View user's profile Post To page top
dewebbster Posted: Fri Jan 13, 2006 1:07 am


Joined: 06 Sep 2005

Posts: 16
Debug method suggestion
I occasionally put such a data dump in a conditional statement that
only shows it to my IP. I have a cable connection that, while
technically (and based on Mindspring`s mailserver`s lookups) is
dynamic, has in fact remained the same for a bit over a year now.
Anyhow, I found it to be a quick-and-dirty way to restrict some
particular functions to myself.

I also have a script that creates a web page and directory and some
mysql tables, that starts with the line

<? if ($_SERVER["REMOTE_ADDR"] != "12.207.205.41") die;

where 12.207.205.41 is of course my own IP.
I like your suggestion also and might try combining the two, cuz
showing the data dump often trashes the layout in a big way. ;)

-m

On Jan 12, 2006, at 11:48 AM, Jeff Bennett wrote:

> I have built an application that generates much of its SQL on
> demand and
> I wanted to track the queries that were being generated. At first
> I was
Reply with quote
Send private message
Post new topic Reply to topic
Display posts from previous:   
 

All times are GMT
Page 1 of 1
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Freelace Website Designer - Customer web design and software building.
Booking Calendar - reservation calendar script
Land Surveying - total station instruments and equipments
China Wholesale - Electronics Products
Character Studio - Tutorials and Help