If there is no result set (e.g. for upsert queries), still allow
fetching to occur without error, i.e. treat it the same way as
an empty result set.

This normalizes behavior between native and emulated prepared
statements and addresses a regression in PHP 7.4.13.
This commit is contained in:
Dharman 2020-12-02 21:24:20 +00:00 committed by Nikita Popov
parent 8588ae7215
commit a83cc03c13
3 changed files with 200 additions and 11 deletions

View file

@ -621,7 +621,12 @@ static int pdo_mysql_stmt_param_hook(pdo_stmt_t *stmt, struct pdo_bound_param_da
static int pdo_mysql_stmt_fetch(pdo_stmt_t *stmt, enum pdo_fetch_orientation ori, zend_long offset) /* {{{ */
{
pdo_mysql_stmt *S = (pdo_mysql_stmt*)stmt->driver_data;
#if PDO_USE_MYSQLND
if (!S->result) {
PDO_DBG_RETURN(0);
}
#ifdef PDO_USE_MYSQLND
zend_bool fetched_anything;
PDO_DBG_ENTER("pdo_mysql_stmt_fetch");
@ -634,6 +639,10 @@ static int pdo_mysql_stmt_fetch(pdo_stmt_t *stmt, enum pdo_fetch_orientation ori
PDO_DBG_RETURN(1);
}
if (!S->stmt && S->current_data) {
mnd_free(S->current_data);
}
#else
int ret;
@ -657,16 +666,6 @@ static int pdo_mysql_stmt_fetch(pdo_stmt_t *stmt, enum pdo_fetch_orientation ori
}
#endif /* PDO_USE_MYSQLND */
if (!S->result) {
strcpy(stmt->error_code, "HY000");
PDO_DBG_RETURN(0);
}
#if PDO_USE_MYSQLND
if (!S->stmt && S->current_data) {
mnd_free(S->current_data);
}
#endif /* PDO_USE_MYSQLND */
if ((S->current_data = mysql_fetch_row(S->result)) == NULL) {
if (!S->H->buffered && mysql_errno(S->H->server)) {
pdo_mysql_error_stmt(stmt);