PHP mysqli_query Parameters Mysqli_store_result and Mysqli_use_result differences

Source: Internet
Author: User

This article mainly introduces the PHP mysqli_query parameters mysqli_store_result and Mysqli_use_result differences, this paper gives the 5 differences between the two parameters, the need for friends can refer to the following

Although NoSQL has become popular, I feel that SQL is still the mainstream
Today, while flipping through PHP manul, found that mysqli query can pass an interesting parameter

@mysqli_query($this->sql,$SQL, ($methodmysqli_use_result  Mysqli_store_result));

The two parameters are interpreted in the PHP Manul.

constant Mysqli_use_result Mysqli_store_result default Mysqli_store_result is used.

If there is nothing to preach, then the default is Mysqli_store_result.

On the Phpmanul, someone said the words if we had to retrieve large amount of the data we use Mysqli_use_result

In fact, the difference between the two parameters is still very large.

(1) The difference is that the rows of the result set are retrieved from the server.
(2) Mysqli_use_result starts the query, but does not actually get any rows
(3) Mysqli_store_result Retrieve all the rows immediately
(4) When mysqli_store_result retrieves a result set from the server, it extracts rows, allocates memory for it, stores it in the client, and then calls Mysqli_fetch_array () to never return an error. Because it simply leaves the row out of the data structure that has preserved the result set, Mysqli_fetch_array () returns null always means that the end of the result set has been reached.
(5) Mysqli_use_result itself does not retrieve any rows, but only initiates a line-by-row retrieval, which means that each row must be called Mysqli_fetch_array () to complete itself. In this case, although normally, Mysqli_fetch_array () returns null still means that the end of the result set has been reached, but may also indicate an error occurred while communicating with the server.

Summarize

Compared with Mysqli_use_result, Mysqli_store_result has high memory and processing requirements because it is maintaining the entire result set on the client, so the memory allocation and the cost of creating the data structure is huge, and if you want to retrieve multiple rows at once, you can Mysqli_use_result.

Mysqli_use_result has a low memory requirement because it needs to allocate enough space for each single line of processing. This is faster because you do not have to create complex data structures for the result set. On the other hand, Mysqli_use_result adds a larger load to the server, and it must keep the rows in the result set until the client appears to be suitable for retrieving all rows.

Reference reading: http://www.manongjc.com/article/1195.html

PHP mysqli_query Parameters Mysqli_store_result and Mysqli_use_result differences

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.