From 4922049213f9630b9cfd8fe196ab770d74c5fc57 Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Thu, 10 Dec 2020 10:28:10 +0100 Subject: Fixed bug #71145 Consume any additional result sets when running INIT_COMMAND. --- NEWS | 2 ++ ext/mysqlnd/mysqlnd_connection.c | 12 +++++++----- ext/pdo_mysql/tests/bug71145.phpt | 25 +++++++++++++++++++++++++ 3 files changed, 34 insertions(+), 5 deletions(-) create mode 100644 ext/pdo_mysql/tests/bug71145.phpt diff --git a/NEWS b/NEWS index 60310b2692..7eeea0c400 100644 --- a/NEWS +++ b/NEWS @@ -38,6 +38,8 @@ PHP NEWS (Nikita) . Fixed bug #70066 (Unexpected "Cannot execute queries while other unbuffered queries"). (Nikita) + . Fixed bug #71145 (Multiple statements in init command triggers unbuffered + query error). (Nikita) - Phpdbg: . Fixed bug #76813 (Access violation near NULL on source operand). (cmb) diff --git a/ext/mysqlnd/mysqlnd_connection.c b/ext/mysqlnd/mysqlnd_connection.c index 1afcc48b2b..5057746fff 100644 --- a/ext/mysqlnd/mysqlnd_connection.c +++ b/ext/mysqlnd/mysqlnd_connection.c @@ -456,12 +456,14 @@ MYSQLND_METHOD(mysqlnd_conn_data, execute_init_commands)(MYSQLND_CONN_DATA * con ret = FAIL; break; } - if (conn->last_query_type == QUERY_SELECT) { - MYSQLND_RES * result = conn->m->use_result(conn, 0); - if (result) { - result->m.free_result(result, TRUE); + do { + if (conn->last_query_type == QUERY_SELECT) { + MYSQLND_RES * result = conn->m->use_result(conn, 0); + if (result) { + result->m.free_result(result, TRUE); + } } - } + } while (conn->m->next_result(conn) != FAIL); } } } diff --git a/ext/pdo_mysql/tests/bug71145.phpt b/ext/pdo_mysql/tests/bug71145.phpt new file mode 100644 index 0000000000..b3f887d7c4 --- /dev/null +++ b/ext/pdo_mysql/tests/bug71145.phpt @@ -0,0 +1,25 @@ +--TEST-- +Bug #71145: Multiple statements in init command triggers unbuffered query error +--SKIPIF-- + +--FILE-- + PDO::ERRMODE_EXCEPTION, + PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8mb4 COLLATE utf8mb4_unicode_ci; SET SESSION sql_mode=traditional', +); +putenv('PDOTEST_ATTR=' . serialize($attr)); + +$pdo = MySQLPDOTest::factory(); +var_dump($pdo->query('SELECT 42')->fetchColumn(0)); + +?> +--EXPECT-- +string(2) "42" -- cgit v1.2.1