Differences between mysql_unbuffered_query and mysql_query in PHP
Source: Internet
Author: User
Mysql_unbuffered_query () sends an SQL query to MySQL, but it does not automatically obtain and cache the result set like mysql_query. On the one hand, this will save a considerable amount of memory in the processing of a large result set and everyone is familiar with mysql_query. next we will briefly introduce mysql_unbuffered_query
Mysql_unbuffered_query
(PHP 4> = 4.0.6, PHP 5) mysql_unbuffered_query -- a row that sends an SQL query to MySQL and does not obtain or cache the result.
Mysql_unbuffered_query () sends an SQL query to MySQL, but it does not automatically obtain and cache the result set like mysql_query. On the one hand, this will save a considerable amount of memory in processing large result sets. On the other hand, you can perform operations on the result set immediately after obtaining the first line, instead of waiting until the entire SQL statement is executed. When multiple databases are connected, you must specify the optional parameter link_identifier.
Note: the benefit of mysql_unbuffered_query () is that mysql_unbuffered_query () and mysql_data_seek () cannot be used on the result set returned by mysql_unbuffered_query (). In addition, before sending a new SQL query to MySQL, you must extract the result rows generated by all non-cached SQL queries.
The above is the explanation of mysql_unbuffered_query in the php Manual. I checked many explanations in the manual online. many people hope to have an instance to better understand the application of this function, according to the explanation, I made an instance for reference only:
$ Link = mysql_connect ('localhost', 'root', 'pwd ');
Mysql_select_db ('dbname ');
$ SQL = "SELECT * FROM tablename ";
/*
Note the following two $ Results. if mysql_query () is used, the mysql_data_seek () function takes effect because the query result is cached.
Mysql_unbuffered_query () function, so mysql_data_seek () does not work, as it is explained in the manual, not cached.
*/
$ Result = mysql_unbuffered_query ($ SQL, $ link );
// $ Result = mysql_query ($ SQL, $ link );
While ($ row = mysql_fetch_array ($ result, MYSQL_NUM )){
Printf ("ID: % s Name: % s", $ row [0], $ row [1]);
}
Mysql_data_seek ($ result, 0 );
While ($ row = mysql_fetch_array ($ result, MYSQL_NUM )){
Printf ("ID: % s Name: % s", $ row [0], $ row [1]);
}
Mysql_free_result ($ result );"
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.