Skip to content

When PDOStatement->execute() failed, then execute successfully, errorInfo() information is incorrect #8626

Closed
@Yurunsoft

Description

@Yurunsoft

Description

The following code:

<?php
$pdo = new PDO('mysql:host=127.0.0.1;dbname=db_imi_test', 'root', 'root', [
    PDO::ATTR_ERRMODE => PDO::ERRMODE_SILENT,
]);
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_SILENT);
$stmt = $pdo->prepare('insert into tb_test(value) values(?)');
// fail
var_dump($stmt->execute([\PHP_INT_MIN]), $stmt->errorCode(), $stmt->errorInfo());

// success
var_dump($stmt->execute([1]), $stmt->errorCode(), $stmt->errorInfo());

Resulted in this output:

bool(false)
string(5) "22003"
array(3) {
  [0]=>
  string(5) "22003"
  [1]=>
  int(1264)
  [2]=>
  string(46) "Out of range value for column 'value' at row 1"
}
bool(true)
string(5) "00000"
array(3) {
  [0]=>
  string(5) "00000"
  [1]=>
  int(1264)
  [2]=>
  string(46) "Out of range value for column 'value' at row 1"
}

But I expected this output instead:

bool(false)
string(5) "22003"
array(3) {
  [0]=>
  string(5) "22003"
  [1]=>
  int(1264)
  [2]=>
  string(46) "Out of range value for column 'value' at row 1"
}
bool(true)
string(5) "00000"
array(3) {
  [0]=>
  string(5) "00000"
  [1]=>
  NULL
  [2]=>
  NULL
}

PHP Version

PHP 7.4、8.0、8.1

Operating System

Ubuntu 20.04

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions