Skip to content

Commit 44b234a

Browse files
committed
Fixed bug #78154
Handle errors during next_result in exec.
1 parent 20e7532 commit 44b234a

File tree

3 files changed

+37
-1
lines changed

3 files changed

+37
-1
lines changed

NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ PHP NEWS
3434
(Kamil Tekiela)
3535
. Fixed bug #63185 (nextRowset() ignores MySQL errors with native prepared
3636
statements). (Nikita)
37+
. Fixed bug #78152 (PDO::exec() - Bad error handling with multiple commands).
38+
(Nikita)
3739

3840
- Phpdbg:
3941
. Fixed bug #76813 (Access violation near NULL on source operand). (cmb)

ext/pdo_mysql/mysql_driver.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,8 @@ static zend_long mysql_handle_doer(pdo_dbh_t *dbh, const char *sql, size_t sql_l
269269
MYSQL_RES* result;
270270
while (mysql_more_results(H->server)) {
271271
if (mysql_next_result(H->server)) {
272-
PDO_DBG_RETURN(1);
272+
pdo_mysql_error(dbh);
273+
PDO_DBG_RETURN(-1);
273274
}
274275
result = mysql_store_result(H->server);
275276
if (result) {

ext/pdo_mysql/tests/bug78152.phpt

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
--TEST--
2+
Bug #78152: PDO::exec() - Bad error handling with multiple commands
3+
--SKIPIF--
4+
<?php
5+
require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'skipif.inc');
6+
require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc');
7+
MySQLPDOTest::skip();
8+
?>
9+
--FILE--
10+
<?php
11+
12+
require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc');
13+
$db = MySQLPDOTest::factory();
14+
MySQLPDOTest::createTestTable($db);
15+
16+
var_dump($db->exec("INSERT INTO test(id, label) VALUES (41, 'x'); INSERT INTO test_bad(id, label) VALUES (42, 'y')"));
17+
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
18+
try {
19+
var_dump($db->exec("INSERT INTO test(id, label) VALUES (42, 'x'); INSERT INTO test_bad(id, label) VALUES (43, 'y')"));
20+
} catch (PDOException $e) {
21+
echo $e->getMessage(), "\n";
22+
}
23+
24+
?>
25+
--CLEAN--
26+
<?php
27+
require dirname(__FILE__) . '/mysql_pdo_test.inc';
28+
MySQLPDOTest::dropTestTable();
29+
?>
30+
--EXPECTF--
31+
Warning: PDO::exec(): SQLSTATE[42S02]: Base table or view not found: 1146 Table '%s.test_bad' doesn't exist in %s on line %d
32+
bool(false)
33+
SQLSTATE[42S02]: Base table or view not found: 1146 Table '%s.test_bad' doesn't exist

0 commit comments

Comments
 (0)