PDO::errorCode — Get the SQLSTATE related to the last operation of the database handle (PHP 5 >= 5.1.0, PECL pdo >= 0.1.0)
mixed PDO::errorCode (void)
Returns a SQLSTATE, a five-character alphanumeric identifier defined in the ANSI SQL standard. Briefly, a SQLSTATE consists of the first two characters of the class value and the last three characters of the subclass value.
If the database handle is not operated on, NULL is returned.
/* Raises an error -- BONES data table does not exist*/$dbh->exec("INSERT INTO bones(skull) VALUES ('lucy')");echo "nPDO::errorCode(): ";print $ dbh->errorCode();?>
The above routine will output:
PDO::errorCode(): 42S02