PHP mysql_unbuffered_query() Function
Definition and Usage
The mysql_unbuffered_query() function sends a SQL query to MySQL (without retrieving / caching the results).
Syntax
mysql_unbuffered_query(query,connection)
Parameters | Description |
---|---|
query | Required. Specifies the SQL query to be sent. Note: The query string should not end with a semicolon. |
connection | Optional. Specifies the SQL connection identifier. If not specified, it uses the last opened connection. |
Description
mysql_unbuffered_query() sends a SQL query 'query' to MySQL, but unlike mysql_query() so that the result set is automatically retrieved and cached. On one hand, this saves considerable memory when dealing with large result sets. On the other hand, you can operate on the result set immediately after getting the first row, without waiting for the entire SQL statement to be executed.
When using multiple database connections, you must specify the optional parameter connection.
Tips and Comments
Note:The benefit of mysql_unbuffered_query() comes at a cost: The connection cannot be used on the result set returned by mysql_unbuffered_query(). mysql_num_rows() and mysql_data_seek()In addition, all the result rows generated by all the uncached SQL queries must be retrieved before sending a new SQL query to MySQL.
Example
<?php $con = mysql_connect("localhost","mysql_user","mysql_pwd"); if (!$con) { die('Could not connect: ' . mysql_error()); } // Large query $sql = "SELECT * FROM Person"; mysql_unbuffered_query($sql,$con); // Start processing data... mysql_close($con); ?>