This PDO prepared statement returns false but does not throw an error
Just wanted to add to this, had similar frustrations from the lack of an error message.
To stop PDO from silently failing, you can set the error mode on the PDO connection.
$dbh = new PDO();
$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
There is also PDO::ERRMODE_WARNING
if you want errors but still continue.
I'm pretty sure that MySQL chokes on the desc
field name - it is a reserved word. You'd have to put it into "`" quotes or, better, change the field name.
As for error reporting, use the errorInfo method. You can make PDO actually output the result of a failed query in the exception, but the default behaviour - I think - is to throw an exception only if the query can't be made at all, but it doesn't fail if the query is faulty.
It also happens when you use PDOStatement::bindValue()
with PDO::PARAM_BOOL
. Solution: just switch to PDO::PARAM_INT
.
I was also facing that error.
I used print_r($con->errorInfo());
it gives me 0000
in 0th
key of array.
Then I matched all column names and figured out that I am using wrong field name.
This saves my day.