Skip to content

Throw error when mysql_stmt_data_seek fails #10419

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
5 changes: 4 additions & 1 deletion ext/mysqli/mysqli_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -1513,7 +1513,10 @@ PHP_FUNCTION(mysqli_stmt_data_seek)

MYSQLI_FETCH_RESOURCE_STMT(stmt, mysql_stmt, MYSQLI_STATUS_VALID);

mysql_stmt_data_seek(stmt->stmt, offset);
if (mysql_stmt_data_seek(stmt->stmt, offset)) {
zend_throw_error(NULL, "The result set buffer is empty");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure about the wording; is there even a buffer in this case. Maybe "Result set is not buffered" (or something like that) gives a better clue about what's wrong.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, currently nothing happens. This is because until now we supported libmysql, which as stated above has this function implemented as void. Now, we are no longer limited by libmysql and we can start throwing an error.
I could also change this to a warning, but I don't see this happening very often and I don't it would be too much to have an error here.

In regards to the text, I wanted to find something rather vague. The error could happen because someone forgot to call store_result(), the PS has only been prepared but not yet executed, or the PS didn't produce any result set. Your suggestion fits the first reason, but not so much the rest. I welcome some brainstorming here.

RETURN_THROWS();
}
}
/* }}} */

Expand Down
6 changes: 6 additions & 0 deletions ext/mysqli/tests/mysqli_stmt_data_seek.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ require_once('skipifconnectfailure.inc');
if (true !== ($tmp = mysqli_stmt_execute($stmt)))
printf("[006] Expecting boolean/true, got %s/%s\n", gettype($tmp), $tmp);

try {
mysqli_stmt_data_seek($stmt, 1);
} catch (Error $exception) {
echo $exception->getMessage() . "\n";
}

$id = null;
if (!mysqli_stmt_bind_result($stmt, $id))
Expand Down Expand Up @@ -87,6 +92,7 @@ require_once('skipifconnectfailure.inc');
?>
--EXPECT--
mysqli_stmt object is not fully initialized
The result set buffer is empty
int(3)
int(1)
int(1)
Expand Down