diff --git a/ext/pdo/pdo_stmt.c b/ext/pdo/pdo_stmt.c index ad7df5c241e37..e88a37465699f 100644 --- a/ext/pdo/pdo_stmt.c +++ b/ext/pdo/pdo_stmt.c @@ -1617,8 +1617,10 @@ PHP_METHOD(PDOStatement, errorInfo) array_init(return_value); add_next_index_string(return_value, stmt->error_code); - if (stmt->dbh->methods->fetch_err) { - stmt->dbh->methods->fetch_err(stmt->dbh, stmt, return_value); + if (strncmp(stmt->error_code, PDO_ERR_NONE, sizeof(PDO_ERR_NONE))) { + if (stmt->dbh->methods->fetch_err) { + stmt->dbh->methods->fetch_err(stmt->dbh, stmt, return_value); + } } error_count = zend_hash_num_elements(Z_ARRVAL_P(return_value)); diff --git a/ext/pdo/tests/gh8626.phpt b/ext/pdo/tests/gh8626.phpt new file mode 100644 index 0000000000000..54b95fbe97b73 --- /dev/null +++ b/ext/pdo/tests/gh8626.phpt @@ -0,0 +1,64 @@ +--TEST-- +GH-8626: PDOStatement->execute() failed, then execute successfully, errorInfo() information is incorrect +--SKIPIF-- + +--FILE-- +setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_SILENT); + +$db->exec('DROP TABLE test'); +$db->exec('CREATE TABLE test (x int NOT NULL)'); + +$stmt = $db->prepare('INSERT INTO test VALUES(?)'); + +// fail +var_dump($stmt->execute([null]), $stmt->errorCode()); +$errorInfo = $stmt->errorInfo(); +if (isset($errorInfo[3])) { + unset($errorInfo[3]); // odbc +} +var_dump($errorInfo); + +$stmt->closeCursor(); // sqlite + +// success +var_dump($stmt->execute([1]), $stmt->errorCode()); +$errorInfo = $stmt->errorInfo(); +if (isset($errorInfo[3])) { + unset($errorInfo[3]); // odbc +} +var_dump($errorInfo); +?> +===DONE=== +--EXPECTF-- +bool(false) +string(%d) "%s" +array(3) { + [0]=> + string(%d) "%s" + [1]=> + int(%d) + [2]=> + string(%d) "%s%w%S" +} +bool(true) +string(5) "00000" +array(3) { + [0]=> + string(5) "00000" + [1]=> + NULL + [2]=> + NULL +} +===DONE=== diff --git a/ext/pdo_pgsql/tests/bug62593.phpt b/ext/pdo_pgsql/tests/bug62593.phpt index 598307a652105..998ce7f37ab9c 100644 --- a/ext/pdo_pgsql/tests/bug62593.phpt +++ b/ext/pdo_pgsql/tests/bug62593.phpt @@ -51,7 +51,7 @@ $expect = 'No errors found'; foreach ($errors as $error) { - if (strpos('Invalid text representation', $error[2]) !== false) + if (null !== $error[2] && strpos('Invalid text representation', $error[2]) !== false) { $expect = 'Invalid boolean found'; }