PDO::errorCode
PDO::errorCode — Gets the SQLSTATE associated with the last operation on the database handle (PHP 5 >= 5.1.0, PECL pdo >= 0.1.0)
Description
Syntax
mixed PDO::errorCode ( void )
Return Values
Returns a SQLSTATE, an identifier defined by the ANSI SQL standard that consists of five letters or digits. Briefly, a SQLSTATE consists of a class value of the first two characters and a subclass value of the last three characters.
Returns NULL if no operation has been performed on the database handle.
Examples
Get a SQLSTATE code
/* 引发一个错误 -- BONES 数据表不存在 */
$dbh->exec("INSERT INTO bones(skull) VALUES ('lucy')");
echo "\nPDO::errorCode(): ";
print $dbh->errorCode();
?>
The above example will output:
PDO::errorCode(): 42S02
Other Extensions
PHP PDO Reference Manual