Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

PDO::errorCode

PDO::errorCode

PHP PDO Reference ManualPHP PDO Reference Manual

PDO::errorCode - Get 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 Value

Returns a SQLSTATE, an identifier of 5 letters or digits defined in the ANSI SQL standard. 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 the database handle has not performed an operation.


Example

Get a SQLSTATE code


/* Trigger an error -- BONES table does not exist */
$dbh->exec("INSERT INTO bones(skull) VALUES ('lucy')");

echo "\nPDO::errorCode(): ";
print $dbh->errorCode();
?>

The above example will output:


PDO::errorCode(): 42S02

PHP PDO Reference ManualPHP PDO Reference Manual