Name
mysql_store_result( )
Synopsis
MYSQL_RES *mysql_store_result(MYSQL *mysql)
Use this to
read and store all of a results set in a MYSQL_RES
structure. When finished with these results, it’s
necessary to use the mysql_free_result( )
function
to free the memory allocated for storing the results set. The
function returns NULL if it’s unsuccessful or if the
query is not the type that would return any results (e.g., an
UPDATE
statement).
... 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); ...
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.