PDOStatement::errorInfo

PHP 教程 · 2019-01-28 20:44:21

PDOStatement::errorInfo — 获取跟上一次语句句柄操作相关的扩展错误信息(PHP 5 >= 5.1.0, PECL pdo >= 0.1.0)

说明

语法

array PDOStatement::errorInfo ( void )

PDOStatement::errorInfo() 返回一个关于上一次语句句柄执行操作的错误信息的数组 。该数组包含下列字段:

元素 信息
0 SQLSTATE 错误码(一个由5个字母或数字组成的在 ANSI SQL 标准中定义的标识符)。
1 具体驱动错误码。
2 具体驱动错误信息。

实例

显示连接到DB2数据库的 PDO_ODBC 连接的 errorInfo() 的字段

<?php
/* 激发一个错误 --  BONES 数据表不存在 */
$sth = $dbh->prepare('SELECT skull FROM bones');
$sth->execute();

echo "\nPDOStatement::errorInfo():\n";
$arr = $sth->errorInfo();
print_r($arr);
?>
<pre>
PDOStatement::errorCode(): 42S02

以上例程会输出:

PDOStatement::errorInfo():
Array
(
    [0] => 42S02
    [1] => -204
    [2] => [IBM][CLI Driver][DB2/LINUX] SQL0204N  "DANIELS.BONES" is an undefined name.  SQLSTATE=42704
)

点击查看所有 PHP 教程 文章: https://www.codercto.com/courses/l/5.html

查看所有标签

Once Upon an Algorithm

Once Upon an Algorithm

Martin Erwig / MIT Press / 2017-9-8 / GBP 22.95

How Hansel and Gretel, Sherlock Holmes, the movie Groundhog Day, Harry Potter, and other familiar stories illustrate the concepts of computing. Picture a computer scientist, staring at a screen and......一起来看看 《Once Upon an Algorithm》 这本书的介绍吧!

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

在线压缩/解压 HTML 代码

JSON 在线解析
JSON 在线解析

在线 JSON 格式化工具

RGB CMYK 转换工具
RGB CMYK 转换工具

RGB CMYK 互转工具