Skip to content

Commit

Permalink
Fixed bug #81037 PDO discards error message text from prepared statement
Browse files Browse the repository at this point in the history
  • Loading branch information
kamil-tekiela committed May 14, 2021
1 parent 28e7add commit 6afbb74
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 1 deletion.
3 changes: 3 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ PHP NEWS
- ODBC:
. Fixed bug #80460 (ODBC doesn't account for SQL_NO_TOTAL indicator). (cmb)

- PDO_MySQL:
. Fixed bug #81037 PDO discards error message text from prepared statement. (Kamil Tekiela)

This comment has been minimized.

Copy link
@cmb69

cmb69 May 14, 2021

Contributor

@kamil-tekiela, lines in NEWS should not exceed 80 (or better 79) characters. Also, the titles of bug reports should be enclosed in parentheses.

This comment has been minimized.

Copy link
@kamil-tekiela

kamil-tekiela May 14, 2021

Author Member

Sorry, is this correct now?

This comment has been minimized.

Copy link
@cmb69

cmb69 May 14, 2021

Contributor

Yes, thank you!


- PDO_ODBC:
. Fixed bug #44643 (bound parameters ignore explicit type definitions). (cmb)

Expand Down
6 changes: 5 additions & 1 deletion ext/pdo_mysql/mysql_driver.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,11 @@ int _pdo_mysql_error(pdo_dbh_t *dbh, pdo_stmt_t *stmt, const char *file, int lin
dbh->is_persistent);

} else {
einfo->errmsg = pestrdup(mysql_error(H->server), dbh->is_persistent);
if (S && S->stmt) {
einfo->errmsg = pestrdup(mysql_stmt_error(S->stmt), dbh->is_persistent);
} else {
einfo->errmsg = pestrdup(mysql_error(H->server), dbh->is_persistent);
}
}
} else { /* no error */
strcpy(*pdo_err, PDO_ERR_NONE);
Expand Down
35 changes: 35 additions & 0 deletions ext/pdo_mysql/tests/bug81037.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
--TEST--
Bug #81037 PDO discards error message text from prepared statement
--SKIPIF--
<?php
if (!extension_loaded('pdo') || !extension_loaded('pdo_mysql')) die('skip not loaded');
require_once(__DIR__ . DIRECTORY_SEPARATOR . 'skipif.inc');
require_once(__DIR__ . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc');
MySQLPDOTest::skip();
?>
--FILE--
<?php
require_once(__DIR__ . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc');

$pdo = MySQLPDOTest::factory();
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$pdo->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
MySQLPDOTest::createTestTable($pdo);

$sql = "SELECT id FROM test WHERE label = :par";
$stmt = $pdo->prepare($sql);
try {
$stmt->execute();
} catch (PDOException $e) {
echo $e->getMessage(), "\n";
}
$data = $stmt->fetchAll(PDO::FETCH_ASSOC);

?>
--CLEAN--
<?php
require __DIR__ . '/mysql_pdo_test.inc';
MySQLPDOTest::dropTestTable();
?>
--EXPECT--
SQLSTATE[HY000]: General error: 2031 No data supplied for parameters in prepared statement

0 comments on commit 6afbb74

Please sign in to comment.