Skip to content

Commit 574b551

Browse files
committed
Merge branch 'PHP-7.4' into PHP-8.0
* PHP-7.4: Fixed bug #81037 PDO discards error message text from prepared statement
2 parents c455f49 + 6afbb74 commit 574b551

File tree

3 files changed

+43
-1
lines changed

3 files changed

+43
-1
lines changed

NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ PHP NEWS
3232
. Fixed bug #81015 (Opcache optimization assumes wrong part of ternary
3333
operator in if-condition). (Nikita)
3434

35+
- PDO_MySQL:
36+
. Fixed bug #81037 PDO discards error message text from prepared statement. (Kamil Tekiela)
37+
3538
- PDO_ODBC:
3639
. Fixed bug #44643 (bound parameters ignore explicit type definitions). (cmb)
3740

ext/pdo_mysql/mysql_driver.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,11 @@ int _pdo_mysql_error(pdo_dbh_t *dbh, pdo_stmt_t *stmt, const char *file, int lin
9494
dbh->is_persistent);
9595

9696
} else {
97-
einfo->errmsg = pestrdup(mysql_error(H->server), dbh->is_persistent);
97+
if (S && S->stmt) {
98+
einfo->errmsg = pestrdup(mysql_stmt_error(S->stmt), dbh->is_persistent);
99+
} else {
100+
einfo->errmsg = pestrdup(mysql_error(H->server), dbh->is_persistent);
101+
}
98102
}
99103
} else { /* no error */
100104
strcpy(*pdo_err, PDO_ERR_NONE);

ext/pdo_mysql/tests/bug81037.phpt

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
--TEST--
2+
Bug #81037 PDO discards error message text from prepared statement
3+
--SKIPIF--
4+
<?php
5+
if (!extension_loaded('pdo') || !extension_loaded('pdo_mysql')) die('skip not loaded');
6+
require_once(__DIR__ . DIRECTORY_SEPARATOR . 'skipif.inc');
7+
require_once(__DIR__ . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc');
8+
MySQLPDOTest::skip();
9+
?>
10+
--FILE--
11+
<?php
12+
require_once(__DIR__ . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc');
13+
14+
$pdo = MySQLPDOTest::factory();
15+
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
16+
$pdo->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
17+
MySQLPDOTest::createTestTable($pdo);
18+
19+
$sql = "SELECT id FROM test WHERE label = :par";
20+
$stmt = $pdo->prepare($sql);
21+
try {
22+
$stmt->execute();
23+
} catch (PDOException $e) {
24+
echo $e->getMessage(), "\n";
25+
}
26+
$data = $stmt->fetchAll(PDO::FETCH_ASSOC);
27+
28+
?>
29+
--CLEAN--
30+
<?php
31+
require __DIR__ . '/mysql_pdo_test.inc';
32+
MySQLPDOTest::dropTestTable();
33+
?>
34+
--EXPECT--
35+
SQLSTATE[HY000]: General error: 2031 No data supplied for parameters in prepared statement

0 commit comments

Comments
 (0)