Skip to content

Commit dbfc9f9

Browse files
committed
Merge branch 'PHP-8.0'
* PHP-8.0: Fixed bug #81037 PDO discards error message text from prepared statement Closes phpGH-6978.
2 parents 3f89063 + 574b551 commit dbfc9f9

File tree

3 files changed

+42
-2
lines changed

3 files changed

+42
-2
lines changed

NEWS

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,8 @@ PHP NEWS
9292
fetching a BLOB). (Nikita)
9393

9494
. PDO MySQL:
95-
. Fixed bug#80908 (PDO::lastInsertId() return wrong). (matt)
95+
. Fixed bug #80908 (PDO::lastInsertId() return wrong). (matt)
96+
. Fixed bug #81037 PDO discards error message text from prepared statement. (Kamil Tekiela)
9697

9798
. PDO ODBC:
9899
. Implement PDO_ATTR_SERVER_VERSION and PDO_ATTR_SERVER_INFO for

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)