954,580 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

The Importance of Testing your Queries in your Database

I just thought I would re-iterate something that I have mentioned a few times in my replies to threads on here in that if your code isn't working, one of the first things to do is actually test your query in the database (i.e. through phpMyAdmin).

The reason I am posting this is that even though I have advised people quite a few times to do this, I had a problem the other day with some very simple coding and very basic update query and I just couldn't work out what the problem was - there was no logical reasoning for it not to work.

Eventually I decided to test the query in phpMyAdmin and guess what, I got an error and I resolved the problem - just a silly missing comma between the 2 fields and values I wanted to update.

The moral of the story: Firstly I should follow my own advice:) and secondly please test your queries in the database - it can save you a lot of time, head scratching and save your sanity.

simplypixie
Posting Pro in Training
447 posts since Oct 2010
Reputation Points: 116
Solved Threads: 82
 

Wow. I never thought that we actually can test our queries in the Database like phpMyAdmin. Thanks for the advice, buddy. Will you please enlighten us on how you'd use the DB to test queries or what part of the DB you use to do that?

I know that missing a comma or apostrophe or anything in queries would waste heaps and heaps of one's time just to debug and see what the problem is.

rotten69
Posting Whiz
346 posts since May 2011
Reputation Points: 3
Solved Threads: 16
 

OK, an example, you have a table called customers and each customer has an id and you want to select all the details for the customer with an id of 1 (this is so simple it should work so it is not a query that will fail, just adjust to match your table and column name(s)).

Login to phpMyAdmin, select the correct database on the left menu and then click the SQL tab towards the top of the page then type or copy in your query, in this case

SELECT * FROM customers WHERE id=1


When you have an error your want to check just copy and paste your query into the SQL form (as above) replacing the $ variables with actual data.

It is the same as using or die(mysql_error()) at the end of your queries in your PHP but just done within the database itself so can sometimes be a bit quicker and easier for testing/debugging.

simplypixie
Posting Pro in Training
447 posts since Oct 2010
Reputation Points: 116
Solved Threads: 82
 

Yes of course.I'm also agree with your opinion.And other thing is,simply we can generate a PHP code for the relevant SQL query via the phpMyAdmin.That's a nice option of that.It reduces the errors when we write the code in PHP..:)

pro_learner
Junior Poster
113 posts since Dec 2010
Reputation Points: 17
Solved Threads: 5
 

Exactly:)

simplypixie
Posting Pro in Training
447 posts since Oct 2010
Reputation Points: 116
Solved Threads: 82
 

I should give that a go. Thanks for sharing this piece of information with us, buddy.

We sometimes learn from others .

rotten69
Posting Whiz
346 posts since May 2011
Reputation Points: 3
Solved Threads: 16
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: