Closes GH-8626: Fix PDOStatement->execute() failed.

Then execute successfully, errorInfo() information is incorrect
This commit is contained in:
Yurun 2022-05-25 11:13:49 +08:00 committed by David Carlier
parent 3a8912fb7c
commit df52903ee0
4 changed files with 72 additions and 3 deletions

3
NEWS
View file

@ -7,6 +7,9 @@ PHP NEWS
. Fixed bug #78139 (timezone_open accepts invalid timezone string argument).
(Derick)
- PDO ODBC:
. Fixed errorInfo() result on successful PDOStatement->execute(). (Yurunsoft)
09 Jun 2022, PHP 8.0.20
- CLI:

View file

@ -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));

64
ext/pdo/tests/gh8626.phpt Normal file
View file

@ -0,0 +1,64 @@
--TEST--
GH-8626: PDOStatement->execute() failed, then execute successfully, errorInfo() information is incorrect
--SKIPIF--
<?php
if (!extension_loaded('pdo')) die('skip');
$dir = getenv('REDIR_TEST_DIR');
if (false == $dir) die('skip no driver');
require_once $dir . 'pdo_test.inc';
PDOTest::skip();
?>
--FILE--
<?php
if (getenv('REDIR_TEST_DIR') === false) putenv('REDIR_TEST_DIR='.__DIR__ . '/../../pdo/tests/');
require_once getenv('REDIR_TEST_DIR') . 'pdo_test.inc';
$db = PDOTest::factory();
$db->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===

View file

@ -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';
}