Skip to content

Commit 4922049

Browse files
committed
Fixed bug #71145
Consume any additional result sets when running INIT_COMMAND.
1 parent f3d5877 commit 4922049

File tree

3 files changed

+34
-5
lines changed

3 files changed

+34
-5
lines changed

NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ PHP NEWS
3838
(Nikita)
3939
. Fixed bug #70066 (Unexpected "Cannot execute queries while other unbuffered
4040
queries"). (Nikita)
41+
. Fixed bug #71145 (Multiple statements in init command triggers unbuffered
42+
query error). (Nikita)
4143

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

ext/mysqlnd/mysqlnd_connection.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -456,12 +456,14 @@ MYSQLND_METHOD(mysqlnd_conn_data, execute_init_commands)(MYSQLND_CONN_DATA * con
456456
ret = FAIL;
457457
break;
458458
}
459-
if (conn->last_query_type == QUERY_SELECT) {
460-
MYSQLND_RES * result = conn->m->use_result(conn, 0);
461-
if (result) {
462-
result->m.free_result(result, TRUE);
459+
do {
460+
if (conn->last_query_type == QUERY_SELECT) {
461+
MYSQLND_RES * result = conn->m->use_result(conn, 0);
462+
if (result) {
463+
result->m.free_result(result, TRUE);
464+
}
463465
}
464-
}
466+
} while (conn->m->next_result(conn) != FAIL);
465467
}
466468
}
467469
}

ext/pdo_mysql/tests/bug71145.phpt

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
--TEST--
2+
Bug #71145: Multiple statements in init command triggers unbuffered query error
3+
--SKIPIF--
4+
<?php
5+
require_once(__DIR__ . DIRECTORY_SEPARATOR . 'skipif.inc');
6+
require_once(__DIR__ . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc');
7+
MySQLPDOTest::skip();
8+
?>
9+
--FILE--
10+
<?php
11+
12+
require_once(__DIR__ . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc');
13+
14+
$attr = array(
15+
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
16+
PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8mb4 COLLATE utf8mb4_unicode_ci; SET SESSION sql_mode=traditional',
17+
);
18+
putenv('PDOTEST_ATTR=' . serialize($attr));
19+
20+
$pdo = MySQLPDOTest::factory();
21+
var_dump($pdo->query('SELECT 42')->fetchColumn(0));
22+
23+
?>
24+
--EXPECT--
25+
string(2) "42"

0 commit comments

Comments
 (0)