]> granicus.if.org Git - php/commitdiff
Fix bug #80837
authorDharman <tekiela246@gmail.com>
Fri, 5 Mar 2021 21:45:27 +0000 (21:45 +0000)
committerNikita Popov <nikita.ppv@gmail.com>
Mon, 15 Mar 2021 13:38:09 +0000 (14:38 +0100)
The error needs to be reported on the statement, not the connection.

NEWS
ext/mysqli/tests/bug80837.phpt [new file with mode: 0644]
ext/mysqlnd/mysqlnd_ps.c

diff --git a/NEWS b/NEWS
index 4ccac5378f8f9f0a6600a90f8549242c489f685b..64b29572afe0465bd6681a40a8731d37fa711048 100644 (file)
--- 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 (file)
index 0000000..71e31aa
--- /dev/null
@@ -0,0 +1,38 @@
+--TEST--
+Bug #80837 Calling stmt_store_result after fetch doesn't throw an error
+--SKIPIF--
+<?php
+require_once 'skipif.inc';
+require_once 'skipifconnectfailure.inc';
+if (!defined('MYSQLI_STORE_RESULT_COPY_DATA')) die('skip requires mysqlnd');
+?>
+--FILE--
+<?php
+require_once "connect.inc";
+
+mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
+$mysqli = new my_mysqli($host, $user, $passwd, $db, $port, $socket);
+
+$mysqli->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--
+<?php
+require_once "clean_table.inc";
+?>
+--EXPECTF--
+Commands out of sync; you can't run this command now
index 12aace6ec27e1b4ff644da2298d8f2ebf31067cf..ce0ad01c8aa84f93e8c459efad4abfe2811b17f1 100644 (file)
@@ -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);
        }