Home >Backend Development >PHP Tutorial >The difference between PHP's mysqli_query parameters MYSQLI_STORE_RESULT and MYSQLI_USE_RESULT, _PHP tutorial

The difference between PHP's mysqli_query parameters MYSQLI_STORE_RESULT and MYSQLI_USE_RESULT, _PHP tutorial

WBOY
WBOYOriginal
2016-07-13 10:17:55861browse

The difference between PHP’s mysqli_query parameters MYSQLI_STORE_RESULT and MYSQLI_USE_RESULT,

Although nosql has become popular, I feel that sql is still mainstream
When I was browsing the php manul today, I found that mysqli queries can pass an interesting parameter

Copy code The code is as follows:

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

These two parameters are explained in the php manul as follows.

Copy code 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 is MYSQLI_STORE_RESULT.

Someone said this on phpmanul: If we have to retrieve large amount of data we use MYSQLI_USE_RESULT

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

(1) The difference lies in retrieving the rows of the result set from the server.
(2) MYSQLI_USE_RESULT starts the query, but does not actually get any rows
(3) MYSQLI_STORE_RESULT retrieves all rows immediately
(4) When MYSQLI_STORE_RESULT retrieves the result set from the server, it extracts the rows, allocates memory for them, and stores them in the client. Then calling mysqli_fetch_array() will never return an error because it only detaches the rows. The data structure of the result set has been retained. The return of NULL by mysqli_fetch_array() always indicates that the end of the result set has been reached.
(5) MYSQLI_USE_RESULT itself does not retrieve any rows, but only starts a row-by-row retrieval, which means that it must be completed by calling mysqli_fetch_array() on each row. That being the case, although under normal circumstances, mysqli_fetch_array() returning NULL still indicates that the end of the result set has been reached, it may also indicate that an error occurred while communicating with the server.

Summary

Compared with MYSQLI_USE_RESULT, MYSQLI_STORE_RESULT has higher memory and processing requirements. Because the entire result set is maintained on the client, the cost of memory allocation and creation of data structures is very huge. If you want to retrieve multiple rows at one time, Available MYSQLI_USE_RESULT.

MYSQLI_USE_RESULT has lower memory requirements because only enough space is allocated for a single row processed each time. This is faster because there is no need to create complex data structures for the result set. MYSQLI_USE_RESULT, on the other hand, places a greater load on the server, which must retain rows in the result set until the client appears suitable to retrieve all rows.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/887353.htmlTechArticleThe difference between PHP's mysqli_query parameters MYSQLI_STORE_RESULT and MYSQLI_USE_RESULT. Although nosql has become popular, I feel that sql is still mainstream today. When looking through the php manul, I found that mysqli...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn