Differences between mysqli_query parameter MYSQLI_STORE_RESULT and MYSQLI_USE_RESULT in PHP

Source: Internet
Author: User
This article mainly introduces the differences between mysqli_query parameter MYSQLI_STORE_RESULT and MYSQLI_USE_RESULT in PHP. This article provides five differences between these two parameters. if you need them, refer to the following: Although nosql becomes popular, but I think SQL is still mainstream.
When turning over php manul today, I found that mysqli queries can pass an interesting parameter.

The code is as follows:


@ Mysqli_query ($ this-> SQL, $ SQL, ($ method? MYSQLI_USE_RESULT: MYSQLI_STORE_RESULT ));

These two parameters are explained in this way on php manul.

The code is as follows:


Either the constant MYSQLI_USE_RESULT or MYSQLI_STORE_RESULT depending on the desired behavior. By default, MYSQLI_STORE_RESULT is used.

If nothing is passed, the default value is MYSQLI_STORE_RESULT.

Someone mentioned this in phpmanul: If we have to retrieve large amount of data we use MYSQLI_USE_RESULT

In fact, the two parameters are quite different.

(1) The difference is that the rows in the result set are retrieved from the server.
(2) MYSQLI_USE_RESULT
(3) MYSQLI_STORE_RESULT: retrieve all rows immediately
(4) MYSQLI_STORE_RESULT extracts rows from the result set retrieved from the server, allocates memory for the rows, stores them in the client, and calls mysqli_fetch_array () to return no errors, because it only disconnects rows from the data structure of the reserved result set, the return value of NULL for mysqli_fetch_array () always indicates that the row has reached the end of the result set.
(5) MYSQLI_USE_RESULT does not retrieve any rows, but starts a row-by-row search. that is to say, you must call mysqli_fetch_array () on each row to complete the search by yourself. In this case, although the return value of mysqli_fetch_array () is NULL, it still indicates that the result set is reached, but it may also indicate an error occurred when communicating with the server.

Summary

Compared with MYSQLI_USE_RESULT, MYSQLI_STORE_RESULT has a high memory and processing requirement. because the entire result set is maintained on the client, it is very costly to allocate memory and create data structures, to retrieve multiple rows at a time, use MYSQLI_USE_RESULT.

MYSQLI_USE_RESULT has a low memory requirement, because you only need to allocate enough space for each processing row. This is faster, because you do not have to create a complex data structure for the result set. On the other hand, MYSQLI_USE_RESULT adds a large load to the server. it must keep the rows in the result set until the client looks suitable for retrieving all rows.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.