Home > php教程 > php手册 > The difference between PHP's mysqli_query parameters MYSQLI_STORE_RESULT and MYSQLI_USE_RESULT

The difference between PHP's mysqli_query parameters MYSQLI_STORE_RESULT and MYSQLI_USE_RESULT

WBOY
Release: 2016-09-22 08:42:12
Original
1687 people have browsed it

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 is still mainstream
When I was browsing php manul today, I found that mysqli query can pass an interesting parameter

@<span style="color: #008080;">mysqli_query</span>(<span style="color: #800080;">$this</span>->sql,<span style="color: #800080;">$SQL</span>,(<span style="color: #800080;">$method</span> ? <span style="color: #008080;">MYSQLI_USE_RESULT</span> : <span style="color: #008080;">MYSQLI_STORE_RESULT</span>));
Copy after login

These two parameters are explained in the php manul like this.

Either the <span style="color: #008080;">constant</span> <span style="color: #008080;">MYSQLI_USE_RESULT</span> or <span style="color: #008080;">MYSQLI_STORE_RESULT</span> depending on the desired behavior. By <span style="color: #0000ff;">default</span>, <span style="color: #008080;">MYSQLI_STORE_RESULT</span> is used.
Copy after login

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 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 rows at one time, you can use 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 seems suitable to retrieve all rows.

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

source:php.cn
Statement of this Website
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
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template