Skip to content

Commit 8283f9d

Browse files
committed
Fix PDOStatement->execute() failed, then execute successfully, errorInfo() information is incorrect
1 parent e05897f commit 8283f9d

File tree

2 files changed

+56
-2
lines changed

2 files changed

+56
-2
lines changed

ext/pdo/pdo_stmt.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1617,8 +1617,10 @@ PHP_METHOD(PDOStatement, errorInfo)
16171617
array_init(return_value);
16181618
add_next_index_string(return_value, stmt->error_code);
16191619

1620-
if (stmt->dbh->methods->fetch_err) {
1621-
stmt->dbh->methods->fetch_err(stmt->dbh, stmt, return_value);
1620+
if (strncmp(stmt->error_code, PDO_ERR_NONE, sizeof(PDO_ERR_NONE))) {
1621+
if (stmt->dbh->methods->fetch_err) {
1622+
stmt->dbh->methods->fetch_err(stmt->dbh, stmt, return_value);
1623+
}
16221624
}
16231625

16241626
error_count = zend_hash_num_elements(Z_ARRVAL_P(return_value));

ext/pdo/tests/gh8626.phpt

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
--TEST--
2+
GH-8626: PDOStatement->execute() failed, then execute successfully, errorInfo() information is incorrect
3+
--SKIPIF--
4+
<?php
5+
if (!extension_loaded('pdo')) die('skip');
6+
$dir = getenv('REDIR_TEST_DIR');
7+
if (false == $dir) die('skip no driver');
8+
require_once $dir . 'pdo_test.inc';
9+
PDOTest::skip();
10+
?>
11+
--FILE--
12+
<?php
13+
if (getenv('REDIR_TEST_DIR') === false) putenv('REDIR_TEST_DIR='.__DIR__ . '/../../pdo/tests/');
14+
require_once getenv('REDIR_TEST_DIR') . 'pdo_test.inc';
15+
16+
$db = PDOTest::factory();
17+
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_SILENT);
18+
19+
@$db->exec("DROP TABLE test");
20+
$db->exec("CREATE TABLE test (x int)");
21+
22+
$stmt = $db->prepare('INSERT INTO test VALUES(?)');
23+
24+
// fail
25+
var_dump($stmt->execute([PHP_INT_MIN]), $stmt->errorCode(), $stmt->errorInfo());
26+
27+
// success
28+
var_dump($stmt->execute([1]), $stmt->errorCode(), $stmt->errorInfo());
29+
?>
30+
===DONE===
31+
--EXPECTF--
32+
bool(false)
33+
string(%d) "%s"
34+
array(3) {
35+
[0]=>
36+
string(%d) "%s"
37+
[1]=>
38+
int(%d)
39+
[2]=>
40+
string(%d) "%s"
41+
}
42+
bool(true)
43+
string(5) "00000"
44+
array(3) {
45+
[0]=>
46+
string(5) "00000"
47+
[1]=>
48+
NULL
49+
[2]=>
50+
NULL
51+
}
52+
===DONE===

0 commit comments

Comments
 (0)