Skip to content

Fix PDOStatement->execute() failed, then execute successfully, errorInfo() information is incorrect #8628

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 9 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions ext/pdo/pdo_stmt.c
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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