In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)05/31 Report--
This article introduces what is the difference between mysql_store_result () and mysql_use_result () function in MySQL. The content is very detailed. Interested friends can use it for reference. I hope it will be helpful to you.
The function mysql_store_result () is similar to mysql_use_result () in that it takes a connection handler parameter and returns a result set. But in fact, there is a big difference between the two. The first difference between the two functions is to retrieve the rows of the result set from the server.
When called, mysql_store_result () immediately retrieves all rows, while mysql_use_result () starts the query but does not actually fetch any rows, and mysql_store_result () assumes that mysql_fetch_row () will then be called to retrieve records. The different ways in which these rows are retrieved cause other differences between the two. This article compares it to learn how to choose the method that works best for your application.
When mysql_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 mysql_fetch_row () without returning an error, because it simply detaches the row from the data structure in which the result set has been retained.
Mysql_fetch_row () returns NULL that always indicates that the end of the result set has been reached. In contrast, mysql_use_result () itself does not retrieve any rows, but just initiates a line-by-line retrieval, meaning that you must call mysql_fetch_row () on each line to do it yourself. In that case, although mysql_fetch_row () 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. You can distinguish the two by calling mysql_errno () and mysql_error ().
Compared with mysql_use_result (), mysql_store_result () has higher memory and processing requirements, because the entire result set is maintained on the client, so memory allocation and data structure creation is very expensive, to run the risk of memory overflow to retrieve large result sets, if you want to retrieve more than one row at a time, you can use mysql_use_result (). Mysql_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. Mysql_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 makes some types of client programs not suitable for mysql_use_result (): interactive client programs that proceed line by line in advance at the user's request (you don't have to make the server wait for the next line just because the user needs a cup of coffee).
A client program that does a lot of processing between row retrieval. In all of these cases, the client program cannot quickly retrieve all rows of the result set, which limits the server and has a negative impact on other client programs, because the table that retrieves the data is read-locked during the query. The client that wants to update the table or any client program that inserts the row is blocked.
After making a query using mysql_query (), you usually use one of these two functions to store the results in a MYSQL_RES * variable.
The main difference between the two is that the results of mysql_use_result () must be "used up at one time", that is, after using it to get a result, you must repeatedly use mysql_fetch_row () to read the results until the function returns null, otherwise if you mysql query again, you will get a "Commands out of sync; you can't run this command now" error. The result obtained by mysql_store_result () is saved, and you don't need to read all the row results before you can make another query. For example, if you make a query and get a series of records, and then use a loop to query the database based on these results, you can only use mysql_store_result ().
What is the difference between the mysql_store_result () and mysql_use_result () functions in MySQL is shared here. I hope the above content can be helpful to you and you can learn more. If you think the article is good, you can share it for more people to see.
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.