PDO::errorInfo

PHP 教程 · 2019-01-28 16:12:23

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 教程 文章: https://codercto.com/courses/l/5.html

查看所有标签

Programming the Mobile Web

Programming the Mobile Web

Maximiliano Firtman / O'Reilly Media / 2010-07-23 / $44.99

* Learn how to use your existing skills to move into mobile web development * Discover the new possibilities of mobile web development, and understand its limitations * Get detailed coverage of ......一起来看看 《Programming the Mobile Web》 这本书的介绍吧!

HTML 压缩/解压工具
HTML 压缩/解压工具

在线压缩/解压 HTML 代码

html转js在线工具
html转js在线工具

html转js在线工具

正则表达式在线测试
正则表达式在线测试

正则表达式在线测试