The difference between mysql_unbuffered_query and mysql_query in PHP

Source: Internet
Author: User

The difference between mysql_unbuffered_query and mysql_query in PHP

For mysql_query Everyone is very familiar with, the following is a brief introduction of the next Mysql_unbuffered_query  

mysql_unbuffered_query  

(PHP 4 >= 4.0.6, PHP 5) mysql_unbuffered_query-Send a SQL query to MySQL without fetching and caching the result rows &NBSP

Description Resource Mysql_unbuffered_query (string query [, Resource link_identifier])  


Mysql_unbuffered_query () sends a SQL query to MySQL, but does not automatically get and cache the result set like mysql_query (). On the one hand, this can save considerable memory when dealing with very large result sets. On the other hand, you can manipulate the result set immediately after getting the first row, rather than waiting for the entire SQL statement to complete. When you use multiple database connections, you must specify an optional parameter, Link_identifier.  

Note: The benefit of mysql_unbuffered_query () is a cost: you cannot use Mysql_num_rows () and mysql_data_ on the result set returned by Mysql_unbuffered_query () Seek (). In addition, before sending a new SQL query to MySQL, you must extract the resulting rows from all non-cached SQL queries.  

The above is mysql_unbuffered_query in the PHP manual explanation, the Internet looked up a lot of explanations of the manual, many people want to have an example to better understand the application of this function, I follow the explanation, I made an example, for reference only:  

$link = mysql_connect (' localhost ', ' root ', ' pwd '); mysql_select_db (' dbname '); $sql = "SELECT * FROM TableName";/* Note the following two $ result, if used with mysql_query (), then the Mysql_data_seek () function will work because the query result is cached, and if the Mysql_unbuffered_query () function is used, then 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); "



Reference Source:
The difference between mysql_unbuffered_query and mysql_query in PHP
Http://www.lai18.com/content/317207.html

The difference between mysql_unbuffered_query and mysql_query in PHP

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.