Skip to content

Commit a59868a

Browse files
committed
Clear mysql error in fetch_into
Closes GH-14256
1 parent 02b7d70 commit a59868a

File tree

4 files changed

+43
-1
lines changed

4 files changed

+43
-1
lines changed

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ PHP NEWS
4343
. Fixed bug GH-14100 (Corrected spelling mistake in php.ini files).
4444
(Marcus Xavier)
4545

46+
- MySQLnd:
47+
. Fix bug GH-14255 (mysqli_fetch_assoc reports error from
48+
nested query). (Kamil Tekiela)
49+
4650
- Opcache:
4751
. Fixed bug GH-14109 (Fix accidental persisting of internal class constant in
4852
shm). (ilutov)

ext/mysqli/mysqli.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -731,7 +731,7 @@ void php_mysqli_fetch_into_hash_aux(zval *return_value, MYSQL_RES * result, zend
731731
/* TODO: We don't have access to the connection object at this point, so we use low-level
732732
* mysqlnd APIs to access the error information. We should try to pass through the connection
733733
* object instead. */
734-
if (MyG(report_mode) & MYSQLI_REPORT_ERROR) {
734+
if (MyG(report_mode) & MYSQLI_REPORT_ERROR && result->conn) {
735735
MYSQLND_CONN_DATA *conn = result->conn;
736736
unsigned error_no = conn->m->get_error_no(conn);
737737
if (error_no) {

ext/mysqli/tests/gh14255.phpt

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
--TEST--
2+
Bug GH-14255 (mysqli_fetch_assoc reports error from nested query)
3+
--EXTENSIONS--
4+
mysqli
5+
--SKIPIF--
6+
<?php
7+
require_once 'skipifconnectfailure.inc';
8+
?>
9+
--FILE--
10+
<?php
11+
12+
require_once 'connect.inc';
13+
14+
mysqli_report(MYSQLI_REPORT_STRICT|MYSQLI_REPORT_ERROR);
15+
16+
$mysqli = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket);
17+
18+
$ca = $mysqli->query('SELECT 1 ');
19+
$c = $ca->fetch_assoc();
20+
try {
21+
$mysqli->query('SELECT non_existent_column');
22+
} catch (Exception $e) {
23+
echo "Caught exception"."\n";
24+
}
25+
$c = $ca->fetch_assoc();
26+
27+
print "done!";
28+
?>
29+
--EXPECTF--
30+
Caught exception
31+
done!

ext/mysqlnd/mysqlnd_result.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -972,6 +972,13 @@ MYSQLND_METHOD(mysqlnd_res, fetch_into)(MYSQLND_RES * result, const unsigned int
972972
bool fetched_anything;
973973
zval *row_data;
974974

975+
// We clean the error here because in unbuffered mode we could receive a new error
976+
// and therefore consumers of this method are checking for errors
977+
MYSQLND_CONN_DATA *conn = result->conn;
978+
if (conn) {
979+
SET_EMPTY_ERROR(conn->error_info);
980+
}
981+
975982
DBG_ENTER("mysqlnd_res::fetch_into");
976983
if (FAIL == result->m.fetch_row(result, &row_data, flags, &fetched_anything)) {
977984
RETVAL_FALSE;

0 commit comments

Comments
 (0)