2

我遇到了以下奇怪的行为:

//assume $dbh is a valid handle
$stmt = $dbh->prepare("UPDATE mytable SET myintcol = :myintval");

$stmt->bindValue(':myintval', 'notanint', PDO::PARAM_INT);
$stmt->execute();
print_r($stmt->errorInfo());

$stmt->bindValue(':myintval', 123, PDO::PARAM_INT);
$stmt->execute();
print_r($stmt->errorInfo());

这将输出:

Array ( [0] => 22P02 [1] => 7 [2] => ERROR: invalid input syntax for integer: "notanint" ) 
Array ( [0] => 00000 [1] => 7 [2] => ERROR: invalid input syntax for integer: "notanint" ) 

尽管第二次执行成功,如00000SQLSTATE 错误代码所示,并通过检查实际表的更新,由于某种原因,该数组的元素 2(文档称为“驱动程序特定错误消息”)保留了先前的消息。这似乎与PDOStatement::errorInfo()http://php.net/manual/en/pdostatement.errorinfo.php)的文档明显相矛盾,该文档声明它将“获取与语句句柄上的最后一个操作相关的扩展错误信息”。

有人有什么解释吗?这不是一个炫耀它只是看起来像一个错误。

4

0 回答 0