Easy Tutorial
❮ Php Mysql Create Php Ref String ❯

PDO::errorCode

PHP PDO Reference Manual

PDO::errorCode — Retrieve an 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 an SQLSTATE, a five-character alphanumeric identifier defined in the ANSI SQL standard. Briefly, an SQLSTATE consists of a two-character class value followed by a three-character subclass value.

Returns NULL if no operation has been performed on the database handle.


Examples

Retrieve an SQLSTATE code

/* Trigger an error -- the 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 Manual

❮ Php Mysql Create Php Ref String ❯