Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the difference between the mysqli_query parameter MYSQLI_STORE_RESULT and MYSQLI_USE_RESULT of PHP

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article introduces the relevant knowledge of "what is the difference between PHP's mysqli_query parameters MYSQLI_STORE_RESULT and MYSQLI_USE_RESULT". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

Although nosql has become popular, I feel that sql is still mainstream.

Today, when I went through php manul, I found that mysqli's query can pass an interesting parameter.

The copy code is as follows:

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

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

The copy 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, it defaults to MYSQLI_STORE_RESULT.

Someone said something like this on phpmanul, If we have to retrieve large amount of data we use MYSQLI_USE_RESULT.

In fact, there is a big difference between these two parameters.

(1) the difference is that 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 immediately retrieves all rows

(4) when MYSQLI_STORE_RESULT retrieves the result set from the server, it extracts the row, allocates memory for it, stores it in the client, and then calls mysqli_fetch_array () and never returns an error, because it simply detaches the row from the data structure in which the result set has been preserved, and mysqli_fetch_array () returns NULL that always indicates that the end of the result set has been reached.

(5) MYSQLI_USE_RESULT itself does not retrieve any rows, but just starts a line-by-line retrieval, that is, you must call mysqli_fetch_array () on each line to do it yourself. In that case, although mysqli_fetch_array () returns NULL normally, it still indicates that the end of the result set has been reached, but it may also indicate that an error occurred while communicating with the server.

Summary

MYSQLI_STORE_RESULT has higher memory and processing requirements than MYSQLI_USE_RESULT, because the entire result set is maintained on the client, so memory allocation and data structure creation are very expensive, and MYSQLI_USE_RESULT is available if you want to retrieve more than one row at a time.

MYSQLI_USE_RESULT has a low memory requirement because you only need to allocate enough space for each single line of processing. This is faster because there is no need to build complex data structures for the result set. MYSQLI_USE_RESULT, on the other hand, puts a heavy load on the server, and it must retain the rows in the result set until the client looks fit to retrieve all rows.

This is the end of the content of "what is the difference between PHP's mysqli_query parameters MYSQLI_STORE_RESULT and MYSQLI_USE_RESULT". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report