Although NoSQL became popular, I felt that SQL was still the mainstream
Today, while flipping through PHP manul, I found that mysqli's query can pass an interesting argument
Copy Code code as follows:
@mysqli_query ($this->sql, $SQL, ($method? Mysqli_use_result:mysqli_store_result));
This is explained in the face of these two parameters on the PHP manul.
Copy Code code as follows:
Either the constant Mysqli_use_result or mysqli_store_result depending on the desired behavior. By default, the Mysqli_store_result is used.
If nothing is passed, it defaults to Mysqli_store_result.
Above Phpmanul someone said such a word if we have to retrieve large amount of data we use Mysqli_use_result
In fact, the difference between the two parameters is still very large.
(1) The difference is in retrieving the rows of the result set from the server.
(2) Mysqli_use_result started the query, but actually did not get any rows
(3) Mysqli_store_result retrieves all rows immediately
(4) Mysqli_store_result Retrieves a result set from the server, extracts the row, allocates memory to it, stores it on the client, and then calls Mysqli_fetch_array () and never returns an error. Because it simply leaves the row out of the data structure that already retains the result set, Mysqli_fetch_array () returns null always indicating that the end of the result set has been reached.
(5) The Mysqli_use_result itself does not retrieve any rows, but simply initiates a line-by-row retrieval, which means that each row must be called Mysqli_fetch_array () to complete itself. This being the case, although Mysqli_fetch_array () returns NULL, it still indicates that the end of the result set is reached at this point, but it may also indicate an error in communicating with the server.
Summarize
Compared to Mysqli_use_result, Mysqli_store_result has a higher memory and processing requirements because it maintains the entire result set on the client, so the cost of allocating memory and creating data structures is huge, and if you want to retrieve multiple rows at once, you can Mysqli_use_result.
Mysqli_use_result has a lower memory requirement because it only needs to allocate enough space for each processing line. This is faster because there is no need to create a complex data structure for the result set. Mysqli_use_result, on the other hand, adds a larger load to the server, and it must keep the rows in the result set until the client looks appropriate to retrieve all the rows.