April 2008
Intermediate to advanced
566 pages
21h 55m
English
mysql_store_result()
MYSQL_RES *mysql_store_result(MYSQL *mysql)
Use this function 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).
Here is an example:
...
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 earlier in this
chapter for an alternative method.
Read now
Unlock full access