Easy Tutorial
❮ Func Directory Getcwd Func Array Krsort ❯

PDO::errorInfo

PHP PDO Reference Manual

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


Description

Syntax

public array PDO::errorInfo ( void )

Return Value

Returns an array containing the error information for the last database operation.

The array contents are as follows:

Element Information
0 SQLSTATE error code (a 5-character alphanumeric identifier defined in the ANSI SQL standard).
1 Driver-specific error code
2 Driver-specific error message

Note: If no operation has been performed on the database handle, it returns NULL.

Example

Displaying error information from PDO_ODBC connection to a DB2 database in errorInfo()

<?php
/* Incorrect SQL syntax */
$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 Reference Manual

❮ Func Directory Getcwd Func Array Krsort ❯