Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
Thread: Debugging with PDO
01-22-2012, 05:11 AM #1
- Join Date
- Jun 2008
- New Jersey
- Thanked 259 Times in 256 Posts
Debugging with PDO
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, 09:33 AM #2
- Join Date
- Jan 2010
- Behind the Wall
- Thanked 372 Times in 368 Posts
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.
The computer is always right. The computer is always right. The computer is always right. Take it from someone who has programmed for over ten years: not once has the computational mechanism of the machine malfunctioned.André Behrens, NY Times Software Developer