PDO::errorInfo
PDO::errorInfo
PDO::errorCode — 返回最后一次操作数据库的错误信息(PHP 5 >= 5.1.0, PECL pdo >= 0.1.0)
说明
语法
public array PDO::errorInfo ( void )
返回值
返回一个数组,该数组包含了最后一次操作数据库的错误信息描述。
数组内容如下:
| 元素 | 信息 |
|---|---|
| 0 | SQLSTATE 错误码 (5个字母或数字组成的在 ANSI SQL 标准中定义的标识符). |
| 1 | 错误代码 |
| 2 | 错误信息 |
注意:如果数据库句柄没有进行操作,则返回 NULL 。
实例
显示errorInfo()中关于PDO_ODBC连接到DB2数据库的错误信息
<?php
/* 错误的SQL语法 */
$stmt = $dbh->prepare('bogus sql');
if (!$stmt) {
echo "\nPDO::errorInfo():\n";
print_r($dbh->errorInfo());
}
?>
以上例程会输出:
PDO::errorInfo():
Array
(
[0] => HY000
[1] => 1
[2] => near "bogus": syntax error
)
相关文章
- PHP 数据类型
- PHP 运算符
- PHP Cookie
- PHP array_column() 函数
- PHP array_diff_key() 函数
- PHP array_fill_keys() 函数
- PHP array_filter() 函数
- PHP array_key_exists() 函数
- PHP array_keys() 函数
- PHP array_merge() 函数
- PHP array_push() 函数
- PHP array_udiff_uassoc() 函数
- PHP array_uintersect() 函数
- PHP array_unshift() 函数
- PHP array_walk() 函数
- PHP array_walk_recursive() 函数
- PHP ksort() 函数
- PHP list() 函数
- PHP reset() 函数
- PHP usort() 函数

PHP PDO 参考手册
