(PHP 5 >= 5.1.0, PHP 7, PECL pdo >= 0.1.0)
PDOStatement::errorCode — Fetch the SQLSTATE associated with the last operation on the statement handle
Identical to PDO::errorCode(), except that PDOStatement::errorCode() only retrieves error codes for operations performed with PDOStatement objects.
Example #1 Retrieving an SQLSTATE code
<?php
/* Provoke an error -- the BONES table does not exist */
$err = $dbh->prepare('SELECT skull FROM bones');
$err->execute();
echo "\nPDOStatement::errorCode(): ";
print $err->errorCode();
?>
The above example will output:
PDOStatement::errorCode(): 42S02