Skip to content

Commit c93b461

Browse files
kamil-tekielanikic
authored andcommitted
Fix bug #80837
The error needs to be reported on the statement, not the connection.
1 parent fc4cd59 commit c93b461

File tree

3 files changed

+41
-1
lines changed

3 files changed

+41
-1
lines changed

NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ PHP NEWS
1717
- MySQLnd:
1818
. Fixed bug #80713 (SegFault when disabling ATTR_EMULATE_PREPARES and
1919
MySQL 8.0). (Nikita)
20+
. Fixed bug #80837 (Calling stmt_store_result after fetch doesn't throw an
21+
error). (Kamil Tekiela)
2022

2123
- opcache:
2224
. Fixed bug #80805 (create simple class and get error in opcache.so). (Nikita)

ext/mysqli/tests/bug80837.phpt

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
--TEST--
2+
Bug #80837 Calling stmt_store_result after fetch doesn't throw an error
3+
--SKIPIF--
4+
<?php
5+
require_once 'skipif.inc';
6+
require_once 'skipifconnectfailure.inc';
7+
if (!defined('MYSQLI_STORE_RESULT_COPY_DATA')) die('skip requires mysqlnd');
8+
?>
9+
--FILE--
10+
<?php
11+
require_once "connect.inc";
12+
13+
mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
14+
$mysqli = new my_mysqli($host, $user, $passwd, $db, $port, $socket);
15+
16+
$mysqli->query('DROP TABLE IF EXISTS test');
17+
$mysqli->query('CREATE TABLE test (b int)');
18+
$mysqli->query('INSERT INTO test VALUES (1),(2),(3)');
19+
20+
$statement = $mysqli->prepare("SELECT b FROM test");
21+
$statement->execute();
22+
$statement->bind_result($name);
23+
$statement->fetch();
24+
try {
25+
$statement->store_result();
26+
} catch (mysqli_sql_exception $e) {
27+
echo $e->getMessage();
28+
}
29+
30+
$mysqli->close();
31+
32+
?>
33+
--CLEAN--
34+
<?php
35+
require_once "clean_table.inc";
36+
?>
37+
--EXPECTF--
38+
Commands out of sync; you can't run this command now

ext/mysqlnd/mysqlnd_ps.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ MYSQLND_METHOD(mysqlnd_stmt, store_result)(MYSQLND_STMT * const s)
9292

9393
/* Nothing to store for UPSERT/LOAD DATA*/
9494
if (!mysqlnd_stmt_check_state(stmt)) {
95-
SET_CLIENT_ERROR(conn->error_info, CR_COMMANDS_OUT_OF_SYNC, UNKNOWN_SQLSTATE, mysqlnd_out_of_sync);
95+
SET_CLIENT_ERROR(stmt->error_info, CR_COMMANDS_OUT_OF_SYNC, UNKNOWN_SQLSTATE, mysqlnd_out_of_sync);
9696
DBG_RETURN(NULL);
9797
}
9898

0 commit comments

Comments
 (0)