Skip to content

Commit

Permalink
Closes GH-8626: Fix PDOStatement->execute() failed.
Browse files Browse the repository at this point in the history
Then execute successfully, errorInfo() information is incorrect
  • Loading branch information
Yurunsoft authored and devnexen committed Jun 2, 2022
1 parent 3a8912f commit df52903
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 3 deletions.
3 changes: 3 additions & 0 deletions NEWS
Expand Up @@ -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:
Expand Down
6 changes: 4 additions & 2 deletions ext/pdo/pdo_stmt.c
Expand Up @@ -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));
Expand Down
64 changes: 64 additions & 0 deletions ext/pdo/tests/gh8626.phpt
@@ -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===
2 changes: 1 addition & 1 deletion ext/pdo_pgsql/tests/bug62593.phpt
Expand Up @@ -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';
}
Expand Down

0 comments on commit df52903

Please sign in to comment.