Firstly, ensure that you have PDO set to throw exceptions on error:
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
Now, ensure that every PDO operation/set of operations is enclosed a try
/catch
block, something like this:
try {
$stmt = $pdo->prepare("SELECT * FROM Whatever");
// ...yada yada yada, your PDO code goes here
} catch (PDOException $e) {
// This will echo the error message along with the file/line no on which the
// exception was thrown. You could e.g. log the string to a file instead.
echo $e->getMessage().' in '.$e->getFile().' on line '.$e->getLine();
}
All exceptions extend from the base Exception
class, and so inherit it's methods and the information it carries about errors.
As a side note, if using PDO with MySQL, ensure that you disable emulated prepared statements. See here for more info on how to do this and why you should.