Name

mysql_unbuffered_query

Synopsis

qresource mysql_unbuffered_query(string query[, cresource connection])

Execute a query without retrieving and buffering the entire result set. This is useful for queries that return large results sets or that are slow to execute. The advantage is that you don’t need the memory resources to store the complete result set, and the function will return before the SQL query has finished. In contrast, the function mysql_query( ) does not return until the query is finished and all of the results have been buffered for subsequent retrieval. The parameters and return values are identical to mysql_query( ).

The disadvantage of mysql_unbuffered_query( ) is that mysql_num_rows( ) cannot be called for the returned query resource handle, because the number of rows returned from the query is not known. The function is otherwise identical in behavior to mysql_query( ).

This function is available in PHP 4.0.6 or later versions.

Warning

Because of the internal MySQL workings of this function, it is important that you finish processing a result set created with mysql_unbuffered_query( ) before creating a new query. Failure to do so may create unpredictable results.

Example

<?php
  $query = "SELECT * FROM presents";
  
  $connection = mysql_pconnect("localhost", "fred", "shhh");
  mysql_select_db("wedding", $connection);
  
  $result = mysql_unbuffered_query($query, $connection);
  
  while ($row = mysql_fetch_array($result))
     echo $row["present"] . "\n";
?>

Get Managing & Using MySQL, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.