Skip to content

Commit df52903

Browse files
Yurunsoftdevnexen
authored andcommitted
Closes GH-8626: Fix PDOStatement->execute() failed.
Then execute successfully, errorInfo() information is incorrect
1 parent 3a8912f commit df52903

File tree

4 files changed

+72
-3
lines changed

4 files changed

+72
-3
lines changed

NEWS

+3
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ PHP NEWS
77
. Fixed bug #78139 (timezone_open accepts invalid timezone string argument).
88
(Derick)
99

10+
- PDO ODBC:
11+
. Fixed errorInfo() result on successful PDOStatement->execute(). (Yurunsoft)
12+
1013
09 Jun 2022, PHP 8.0.20
1114

1215
- CLI:

ext/pdo/pdo_stmt.c

+4-2
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

+64
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
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 NOT NULL)');
21+
22+
$stmt = $db->prepare('INSERT INTO test VALUES(?)');
23+
24+
// fail
25+
var_dump($stmt->execute([null]), $stmt->errorCode());
26+
$errorInfo = $stmt->errorInfo();
27+
if (isset($errorInfo[3])) {
28+
unset($errorInfo[3]); // odbc
29+
}
30+
var_dump($errorInfo);
31+
32+
$stmt->closeCursor(); // sqlite
33+
34+
// success
35+
var_dump($stmt->execute([1]), $stmt->errorCode());
36+
$errorInfo = $stmt->errorInfo();
37+
if (isset($errorInfo[3])) {
38+
unset($errorInfo[3]); // odbc
39+
}
40+
var_dump($errorInfo);
41+
?>
42+
===DONE===
43+
--EXPECTF--
44+
bool(false)
45+
string(%d) "%s"
46+
array(3) {
47+
[0]=>
48+
string(%d) "%s"
49+
[1]=>
50+
int(%d)
51+
[2]=>
52+
string(%d) "%s%w%S"
53+
}
54+
bool(true)
55+
string(5) "00000"
56+
array(3) {
57+
[0]=>
58+
string(5) "00000"
59+
[1]=>
60+
NULL
61+
[2]=>
62+
NULL
63+
}
64+
===DONE===

ext/pdo_pgsql/tests/bug62593.phpt

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ $expect = 'No errors found';
5151

5252
foreach ($errors as $error)
5353
{
54-
if (strpos('Invalid text representation', $error[2]) !== false)
54+
if (null !== $error[2] && strpos('Invalid text representation', $error[2]) !== false)
5555
{
5656
$expect = 'Invalid boolean found';
5757
}

0 commit comments

Comments
 (0)