PDO::errorInfo

PHP PDO 参考手册PHP PDO Reference Manual

PDO::errorCode — Returns the error information from the last database operation (PHP 5 >= 5.1.0, PECL pdo >= 0.1.0)


Description

Syntax

public array PDO::errorInfo ( void )

Return Values

Returns an array that contains the error information description for the last database operation.

The array contains the following:

Element Information
0 SQLSTATE error code (an identifier composed of 5 letters or digits as defined in the ANSI SQL standard).
1 Error code
2 Error message

Note:If the database handle has not performed an operation, NULL is returned.

Examples

Display the error information from errorInfo() regarding PDO_ODBC connecting to a 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
)

PHP PDO 参考手册PHP PDO Reference Manual

Other Extensions