diff --git a/ext/mysqli/mysqli_api.c b/ext/mysqli/mysqli_api.c index ccb1da6af738..c667712f85fe 100644 --- a/ext/mysqli/mysqli_api.c +++ b/ext/mysqli/mysqli_api.c @@ -1488,6 +1488,15 @@ PHP_FUNCTION(mysqli_stmt_data_seek) MYSQLI_FETCH_RESOURCE_STMT(stmt, mysql_stmt, MYSQLI_STATUS_VALID); + if (!stmt->stmt->data || !stmt->stmt->data->result || !stmt->stmt->data->result->stored_data) { + if (hasThis()) { + zend_throw_error(NULL, "mysqli_stmt::data_seek(): No result set associated with the statement"); + } else { + zend_throw_error(NULL, "mysqli_stmt_data_seek(): No result set associated with the statement"); + } + RETURN_THROWS(); + } + mysql_stmt_data_seek(stmt->stmt, offset); } /* }}} */ diff --git a/ext/mysqli/tests/mysqli_stmt_data_seek.phpt b/ext/mysqli/tests/mysqli_stmt_data_seek.phpt index a36daebc7951..e4b913229cd0 100644 --- a/ext/mysqli/tests/mysqli_stmt_data_seek.phpt +++ b/ext/mysqli/tests/mysqli_stmt_data_seek.phpt @@ -25,6 +25,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)) @@ -82,6 +87,7 @@ require_once 'skipifconnectfailure.inc'; ?> --EXPECT-- mysqli_stmt object is not fully initialized +mysqli_stmt_data_seek(): No result set associated with the statement int(3) int(1) int(1)