Home  >  Article  >  类库下载  >  The difference between MYSQLI_STORE_RESULT and MYSQLI_USE_RESULT

The difference between MYSQLI_STORE_RESULT and MYSQLI_USE_RESULT

高洛峰
高洛峰Original
2016-10-10 09:37:281255browse

This article mainly introduces the difference between PHP's mysqli_query parameters MYSQLI_STORE_RESULT and MYSQLI_USE_RESULT. This article gives 5 differences between these two parameters. Friends in need can refer to it

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

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

These two parameters are explained in php manul like this.

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, it defaults to 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 is in retrieving the rows of the result set from the server.
(2) MYSQLI_USE_RESULT starts the query, but does not actually fetch any rows
(3) MYSQLI_STORE_RESULT retrieves all rows immediately
(4) MYSQLI_STORE_RESULT When the result set is retrieved from the server, the rows are extracted and memory is allocated for them, Stored in the client, subsequent calls to mysqli_fetch_array() will never return an error because it only removes the rows from the data structure that already holds the result set. 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 data at one time OK, MYSQLI_USE_RESULT is available.

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 seems suitable to retrieve all rows.


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

Related articles

See more