View Full Version : Debugging with PDO

01-22-2012, 04:11 AM
I was curious how people debug a PDO statement.

I recently started working with PHP's PDO, and put together a query. It kept failing, and I couldn't figure out why. The code executed, so it was obviously an issue with my MySQL statement. I checked the statement in a console with test data, and it worked fine, but the PDO statement refused to work. I was using the colon placeholders, bindValue, and execute, and after a bunch of testing, I realized it was because the variable I was feeding to bindValue was being changed due to my requesting a GET instead of a POST.

In the past, it would have been a simple thing of echoing the query to see where I went wrong. I haven't found a way to do the same with a prepared statement. I tried debugDumpParams, but it didn't help at all (not even sure what use it is).

How do people debug prepared statements? Am I relegated to creating new debug code, or simply being hyper careful?

01-28-2012, 08:33 AM
usually I run PDO in Exception mode to get every SQL error thrown in PHP.

for the GET/POST problem I donít see something you can do within PDO itself (it just passes the data to the DB server), though using $_GET instead of $_POST should have caused PHP to issue an "undefined index" warning (unless this is disabled). you may consider to use a custom error handler to get notified of these.