Technologies Ignited

Technologies Ignited

Debugging a PDO statement in a PHP system

leave a comment »

If you are wondering how to debug a PDO statement here are some advices.
There is no such thing as a final statement. If a statement looks like this:

SELECT group_id, count(*) AS cnt FROM chat_visited
WHERE user_id = :i_user_id GROUP BY group_id;

this is the way it’s sent to the database.
The parameters you bind withi this statement are declared as variables and the connecting between them happens on the database layer.

So how to debug such statement?

echo $stm->debugDumpParams();

will give you detailed information about the statement.

echo var_export($stm->errorInfo());

will give you the error of the statement.
In most cases the second line will be enought to debug your statements.

Written by wyand

7 May 2012 at 13:56

Posted in PHP

Tagged with ,

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: