Skip to content

Clear mysql error in fetch_into #14256

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ext/mysqli/mysqli.c
Original file line number Diff line number Diff line change
Expand Up @@ -731,7 +731,7 @@ void php_mysqli_fetch_into_hash_aux(zval *return_value, MYSQL_RES * result, zend
/* TODO: We don't have access to the connection object at this point, so we use low-level
* mysqlnd APIs to access the error information. We should try to pass through the connection
* object instead. */
if (MyG(report_mode) & MYSQLI_REPORT_ERROR) {
if (MyG(report_mode) & MYSQLI_REPORT_ERROR && result->conn) {
MYSQLND_CONN_DATA *conn = result->conn;
unsigned error_no = conn->m->get_error_no(conn);
if (error_no) {
Expand Down
31 changes: 31 additions & 0 deletions ext/mysqli/tests/gh14255.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
--TEST--
Bug GH-14255 (mysqli_fetch_assoc reports error from nested query)
--EXTENSIONS--
mysqli
--SKIPIF--
<?php
require_once 'skipifconnectfailure.inc';
?>
--FILE--
<?php

require_once 'connect.inc';

mysqli_report(MYSQLI_REPORT_STRICT|MYSQLI_REPORT_ERROR);

$mysqli = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket);

$ca = $mysqli->query('SELECT 1 ');
$c = $ca->fetch_assoc();
try {
$mysqli->query('SELECT non_existent_column');
} catch (Exception $e) {
echo "Caught exception"."\n";
}
$c = $ca->fetch_assoc();

print "done!";
?>
--EXPECTF--
Caught exception
done!
7 changes: 7 additions & 0 deletions ext/mysqlnd/mysqlnd_result.c
Original file line number Diff line number Diff line change
Expand Up @@ -972,6 +972,13 @@ MYSQLND_METHOD(mysqlnd_res, fetch_into)(MYSQLND_RES * result, const unsigned int
bool fetched_anything;
zval *row_data;

// We clean the error here because in unbuffered mode we could receive a new error
// and therefore consumers of this method are checking for errors
MYSQLND_CONN_DATA *conn = result->conn;
if (conn) {
SET_EMPTY_ERROR(conn->error_info);
}

DBG_ENTER("mysqlnd_res::fetch_into");
if (FAIL == result->m.fetch_row(result, &row_data, flags, &fetched_anything)) {
RETVAL_FALSE;
Expand Down
Loading