Technologies Ignited

Debugging a PDO statement in a PHP system

Advertisements

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.

Advertisements

Advertisements