mysql_unbuffered_query() function for PHP

What is mysql_unbuffered_query() function in PHP?
How does mysql_unbuffered_query() works?


Mysql function mysql_unbuffered_query() send an SQL query to MySQL, without fetching and buffering the result rows
resource mysql_unbuffered_query(string query [, resource link_identifier])

Returns the query handle for SELECT queries, TRUE/FALSE for other queries, or FALSE on failure.
mysql_unbuffered_query() sends a SQL query to MySQL, without fetching and buffering the result rows automatically, as mysql_query() does. This saves a considerable amount of memory with SQL queries that produce large result sets.
It executes the query and returns a resource pointing to the result of the query while MySQL is still working, which means you can start reading the result before the query has finished. When using multiple DB-connects, you have to specify the optional parameter link_identifier.
You cannot use mysql_num_rows() and mysql_data_seek() on a result set returned from mysql_unbuffered_query().

$link = mysql_pconnect("mysql_host", "mysql_user", "mysql_password")
or die ("Could not connect");
//select database
if (!mysql_select_db("my_database", $link)) {
echo " ERROR NO: " . mysql_errno($link) . "n";
$sql="select * from my_table";
$result =mysql_unbuffered_query($sql,$link);
// start working with data
while ($row = mysql_fetch_assoc($result)) {
echo $row["field1"];


See also: mysql_query().

PHP Topics

Ask Questions

Ask Question