PDO::errorCode — Returns the error message of the last database operation (PHP 5 >= 5.1.0, PECL pdo >= 0.1.0)
public array PDO::errorInfo ( void )
Returns an array containing the error message description of the last database operation.
The contents of the array are as follows:
element | information |
---|---|
0 | SQLSTATE error code (a 5-letter or numeric identifier defined in the ANSI SQL standard). |
1 | error code |
2 | error message |
Note: If the database handle is not operated, NULL is returned.
<?php/* Wrong SQL syntax*/$stmt = $dbh->prepare('bogus sql');if (!$stmt) { echo "nPDO::errorInfo():n"; print_r($ dbh->errorInfo());}?>
The above routine will output:
PDO::errorInfo():Array( [0] => HY000 [1] => 1 [2] => near "bogus": syntax error)