Name
mysql_fetch_row( )
Synopsis
MYSQL_ROW mysql_fetch_row(MYSQL_RES *result)
Use this to retrieve the next row of a results set. When there are no more rows to retrieve, the function returns NULL. Here is a fairly complete example using this function:
#include <stdio.h> #include <stdlib.h> #include <mysql/mysql.h> int main( ) { MYSQL *mysql; MYSQL_RES *result; MYSQL_ROW row; MYSQL_FIELD *field; int i, num_fields; mysql = mysql_init(NULL); mysql_real_connect(mysql,"localhost","user","password", "workrequests",0,NULL,0); mysql_query(mysql,"SELECT * FROM users"); result = mysql_store_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); mysql_close(mysql); exit(EXIT SUCCESS); }
Although this example is a complete program, it’s missing the usual error checking.
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.