Name

mysql_use_result( )

Synopsis

MYSQL_RES *mysql_use_result(MYSQL *mysql)

Use this to read the results of a query, one row at a time. This functions 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 without finishing with the results that are in use from the first query. 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.

...
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 for an alternative method.

Get MySQL in a Nutshell 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.