Name
mysql_use_result()
Synopsis
MYSQL_RES *mysql_use_result(MYSQL *mysql)
Use this function to read the results of a query, one row at
a time. This works in a way similar to the
mysql_store_result() function, except that
function retrieves all of the data at once and stores it for later
use. The mysql_use_result() function is best
used when a results set would be large and speed of processing is a
concern. With this function, processing may be started sooner without
having to wait for all of the data to be retrieved. One drawback to
this function is that other queries cannot be run while the results
from the first query are in use. Also, functions such as
mysql_data_seek() cannot be used and the
return value from running mysql_num_rows() is
altered, because the complete size of the results set is unknown. Here
is an example:
...
mysql_query(mysql, "SELECT * FROM clients");
result = mysql_use_result(mysql);
num_fields = mysql_field_count(mysql);
while((row = mysql_fetch_row(result)) != NULL)
{
for(i = 0; i < num_fields; i++)
{
field = mysql_fetch_field_direct(result, i);
printf("%s: %s, ", field->name, row[i]);
}
printf("\n");
}
mysql_free_result(result);
...See the example for the
mysql_fetch_row() function earlier in this
chapter for an alternative method.
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access