|
|
mysql_unbuffered_query() - PHP
|
Views : 394
|
|
Tagged in : PHP
|
|
|
Report This Scrap as Inappropriate We request you to choose the appropriate categroy and subcategory that suits your
objectionable concern about the scrap, So that our team can review and find out whether it violates our Guidelines or the
scrap is not suitable for all viewers.
|
So far we've been using the mysql_query() function to do all our data searching in PHP, and it works well enough for the vast majority of cases. However, consider this: how does the mysql_num_rows() function know how many rows mysql_query() returned? The answer is simple: mysql_query() runs the query, and fetches and buffers it all so that it has the complete result set available. The mysql_num_rows() function then has access to all the rows, and so can return the true row count.
But, what do you do if you have a large number of rows and don't want to wait before MySQL has finished fetching them all before you start using them? In this scenario, mysql_unbuffered_query() comes into play: 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 before the query has finished.
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 working with data
mysql_close($con);
?>
Note:You cannot use mysql_num_rows() and mysql_data_seek() on a result set returned from mysql_unbuffered_query(). |
|
By Rekha, On - 2009-12-04 |
|
|
|