We help IT Professionals succeed at work.

Testing Parametrized Queries

APD Toronto
APD Toronto asked
Hi Experts,

I am starting a new application and I decided to use parametrized queries, which is my first time using them.

However, when I used regular queries with variable substitution, I could just echo my query, then copy it into phpMyAdmin and play with it to see if something is wrong with my SQL or with my values. Now, that my values and SQL is separate, is there any way I can temporarily converse my parametrized query to show on my browser with the appropriate values?

Thank you
Watch Question

Most Valuable Expert 2011
Top Expert 2016
You might be better off to use some automation for this process.  You can use PHPUnit and Mockery to achieve what you need.  These testing tools allow you to set up test assertions that detail the expectations from each element of a unit test.  It takes a little bit of time to set up the unit tests for your systems, but once you have done it you can rerun all of the unit tests in a matter of seconds.  It becomes a standard part of the development process, before anything is pushed to the repository.  And since you can rerun the entire suite of tests so quickly (a single command), you can test almost every little change as you refactor to be sure a change in one place did not break anything in another place!

Have a look at the man pages and know that you'll find most professional developers using exactly these same tools!