2

I've encountered the following bizarre behavior:

//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());

This will output:

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" ) 

Although the 2nd execution succeeds, as indicated by the 00000 SQLSTATE error code and by checking the actual table for the update, for some reason element 2 of this array, what the docs call "Driver specific error message", retains the previous message. This seems to plainly contradict the docs for PDOStatement::errorInfo() (http://php.net/manual/en/pdostatement.errorinfo.php) which state that it will "Fetch extended error information associated with the last operation on the statement handle".

Does anyone have any explanation? It's not a showstopper it just seems like a bug.

Danny
  • 439
  • 5
  • 9

0 Answers0