Skip to content

Commit 637c116

Browse files
ext/mysqli: Throw error when mysql_stmt_data_seek cannot be executed (php#10419)
1 parent 355571c commit 637c116

2 files changed

Lines changed: 15 additions & 0 deletions

File tree

ext/mysqli/mysqli_api.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1488,6 +1488,15 @@ PHP_FUNCTION(mysqli_stmt_data_seek)
14881488

14891489
MYSQLI_FETCH_RESOURCE_STMT(stmt, mysql_stmt, MYSQLI_STATUS_VALID);
14901490

1491+
if (!stmt->stmt->data || !stmt->stmt->data->result || !stmt->stmt->data->result->stored_data) {
1492+
if (hasThis()) {
1493+
zend_throw_error(NULL, "mysqli_stmt::data_seek(): No result set associated with the statement");
1494+
} else {
1495+
zend_throw_error(NULL, "mysqli_stmt_data_seek(): No result set associated with the statement");
1496+
}
1497+
RETURN_THROWS();
1498+
}
1499+
14911500
mysql_stmt_data_seek(stmt->stmt, offset);
14921501
}
14931502
/* }}} */

ext/mysqli/tests/mysqli_stmt_data_seek.phpt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ require_once 'skipifconnectfailure.inc';
2525
if (true !== ($tmp = mysqli_stmt_execute($stmt)))
2626
printf("[006] Expecting boolean/true, got %s/%s\n", gettype($tmp), $tmp);
2727

28+
try {
29+
mysqli_stmt_data_seek($stmt, 1);
30+
} catch (Error $exception) {
31+
echo $exception->getMessage() . "\n";
32+
}
2833

2934
$id = null;
3035
if (!mysqli_stmt_bind_result($stmt, $id))
@@ -82,6 +87,7 @@ require_once 'skipifconnectfailure.inc';
8287
?>
8388
--EXPECT--
8489
mysqli_stmt object is not fully initialized
90+
mysqli_stmt_data_seek(): No result set associated with the statement
8591
int(3)
8692
int(1)
8793
int(1)

0 commit comments

Comments
 (0)