Sometimes, we want to view query error in PDO PHP.
In this article, we’ll look at how to view query error in PDO PHP.
How to view query error in PDO PHP?
To view query error in PDO PHP, we can use the errorInfo
method.
For instance, we write
if (!$st->execute()) {
print_r($st->errorInfo());
}
to check if the $st
statement failed to execute by checking if execute
returns false
.
If it does, then we call errorInfo
to get the error and print it with print_r
.
Conclusion
To view query error in PDO PHP, we can use the errorInfo
method.