When I have something like this:
$row = mysqli_fetch_assoc($result);
Does $result now have one less row in it?
If I loop mysqli_fetch_assoc
through all the $result
, will it be empty afterwards?
When I have something like this:
$row = mysqli_fetch_assoc($result);
Does $result now have one less row in it?
If I loop mysqli_fetch_assoc
through all the $result
, will it be empty afterwards?
$result is a resource pointer, it is not possible to add to, or remove data from it. It will give you a result and internally move on to the next record. The result as such is untouched.
The manual page provides additional info.
$result
is a reference to a SQL result set, which contains all the rows returned in response to your query. Calling mysqli_fetch_assoc
simply moves the result set's internal pointer further down the list of rows, eventually pointing to NULL
(end of list). The rows are all still there, you haven't removed any of them: you've simply traversed the list, and you could run through them again by using something like mysqli_data_seek
to reset the internal pointer to a specific row.
To clear $result
, you'd need to call mysqli_free_result
to "free" the result set.
After the execution of that line, $result
remains as a resource pointer, and can be used by other functions where applicable for further processing with $result
as the reference to the database.
You can either unset it, or mysqli_free_result($result);