From c93b461ad70e341f1b01f5910f3cfc3055a3941e Mon Sep 17 00:00:00 2001 From: Dharman Date: Fri, 5 Mar 2021 21:45:27 +0000 Subject: Fix bug #80837 The error needs to be reported on the statement, not the connection. --- NEWS | 2 ++ ext/mysqli/tests/bug80837.phpt | 38 ++++++++++++++++++++++++++++++++++++++ ext/mysqlnd/mysqlnd_ps.c | 2 +- 3 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 ext/mysqli/tests/bug80837.phpt diff --git a/NEWS b/NEWS index 4ccac5378f..64b29572af 100644 --- a/NEWS +++ b/NEWS @@ -17,6 +17,8 @@ PHP NEWS - MySQLnd: . Fixed bug #80713 (SegFault when disabling ATTR_EMULATE_PREPARES and MySQL 8.0). (Nikita) + . Fixed bug #80837 (Calling stmt_store_result after fetch doesn't throw an + error). (Kamil Tekiela) - opcache: . Fixed bug #80805 (create simple class and get error in opcache.so). (Nikita) diff --git a/ext/mysqli/tests/bug80837.phpt b/ext/mysqli/tests/bug80837.phpt new file mode 100644 index 0000000000..71e31aa31b --- /dev/null +++ b/ext/mysqli/tests/bug80837.phpt @@ -0,0 +1,38 @@ +--TEST-- +Bug #80837 Calling stmt_store_result after fetch doesn't throw an error +--SKIPIF-- + +--FILE-- +query('DROP TABLE IF EXISTS test'); +$mysqli->query('CREATE TABLE test (b int)'); +$mysqli->query('INSERT INTO test VALUES (1),(2),(3)'); + +$statement = $mysqli->prepare("SELECT b FROM test"); +$statement->execute(); +$statement->bind_result($name); +$statement->fetch(); +try { + $statement->store_result(); +} catch (mysqli_sql_exception $e) { + echo $e->getMessage(); +} + +$mysqli->close(); + +?> +--CLEAN-- + +--EXPECTF-- +Commands out of sync; you can't run this command now diff --git a/ext/mysqlnd/mysqlnd_ps.c b/ext/mysqlnd/mysqlnd_ps.c index 12aace6ec2..ce0ad01c8a 100644 --- a/ext/mysqlnd/mysqlnd_ps.c +++ b/ext/mysqlnd/mysqlnd_ps.c @@ -92,7 +92,7 @@ MYSQLND_METHOD(mysqlnd_stmt, store_result)(MYSQLND_STMT * const s) /* Nothing to store for UPSERT/LOAD DATA*/ if (!mysqlnd_stmt_check_state(stmt)) { - SET_CLIENT_ERROR(conn->error_info, CR_COMMANDS_OUT_OF_SYNC, UNKNOWN_SQLSTATE, mysqlnd_out_of_sync); + SET_CLIENT_ERROR(stmt->error_info, CR_COMMANDS_OUT_OF_SYNC, UNKNOWN_SQLSTATE, mysqlnd_out_of_sync); DBG_RETURN(NULL); } -- cgit v1.2.1