Skip to content

Commit 05efcc2

Browse files
committed
Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2: Clear mysql error in fetch_into
2 parents cce922e + a59868a commit 05efcc2

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
@@ -35,6 +35,10 @@ PHP NEWS
3535
. Fixed build regression on systems without C++17 compilers. (Calvin Buckley,
3636
Peter Kokot)
3737

38+
- MySQLnd:
39+
. Fix bug GH-14255 (mysqli_fetch_assoc reports error from
40+
nested query). (Kamil Tekiela)
41+
3842
- Opcache:
3943
. Fixed bug GH-14109 (Fix accidental persisting of internal class constant in
4044
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
@@ -970,6 +970,13 @@ MYSQLND_METHOD(mysqlnd_res, fetch_into)(MYSQLND_RES * result, const unsigned int
970970
bool fetched_anything;
971971
zval *row_data;
972972

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

0 commit comments

Comments
 (0)