Debugging PDO queries
The PHP method
PDOStatment::errorInfo()
retrieves information about the last operation on the statement. But when the
result of PDOStatment::execute()
is FALSE
it may not
return much useful information:
Array ( [0] => 00000 [1] => [2] => )
To get more data, check the value of PDO::ATTR_ERRMODE
. The
default value is PDO::ERRMODE_SILENT
but that silences errors
during PDO execution. During development it can help to change it to
PDO::ERRMODE_WARNING
to emit an E_WARNING
when an error occurs.
$pdo = new PDO(...); $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);
To get the details of the prepared statement use
PDOStatment::debugDumpParams()
.
It will output the query and the passed values.