PDO :: errorInfo
PDO :: errorCode - Returns the last error message database operations (PHP 5> = 5.1.0, PECL pdo> = 0.1.0)
Explanation
grammar
public array PDO::errorInfo ( void )
return value
It returns an array containing the last database operation error description.
Contents of the array as follows:
element | information |
---|---|
0 | SQLSTATE error code (5 letters or numbers in the ANSI SQL standard defined identifiers of). |
1 | error code |
2 | Error Message |
Note: If you do not have to operate the database handle, returns NULL.
Examples
Display errorInfo () error message about PDO_ODBC connect to the DB2 database
<?php /* 错误的SQL语法 */ $stmt = $dbh->prepare('bogus sql'); if (!$stmt) { echo "\nPDO::errorInfo():\n"; print_r($dbh->errorInfo()); } ?>
The above example will output:
PDO::errorInfo(): Array ( [0] => HY000 [1] => 1 [2] => near "bogus": syntax error )