Name
mysql_store_result —
Synopsis
MYSQL_RES *mysql_store_result(MYSQL *mysql)
Reads
the entire result of a query and stores it in a
MYSQL_RES
structure. Either this function or
mysql_use_result
must be called to access return
information from a query. You must call
mysql_free_result
to free the
MYSQL_RES
structure when you are done with it.
The function returns a null value in the case of an error. The
function also returns a null value if the query was not of a type
that returns data (such as an INSERT
or
UPDATE
query). If you receive a null pointer and
are not sure if the query was supposed to return data or not, you can
call mysql_field_count
to find the number of
fields the query was supposed to return. If zero, then it was a
non-SELECT
statement, and the pointer should be
null. Otherwise, an error has occurred.
If the query was a SELECT
-type statement, but
happens to contain no data, this function will still return a valid
(but empty) MYSQL_RES
structure (it will not be a
null pointer).
Example
MYSQL_RES results; mysql_query(&mysql, "SELECT * FROM people"); results = mysql_store_result(&mysql); /* 'results' should now contain all of the information from the 'people' table */ if (!results) { printf("An error has occurred!\n"); } /* 'query' is some query string we obtained elsewhere, we're not sure what it is... */ mysql_query(&mysql, query); results = mysql_store_result(&mysql); if (!results) { /* An error might have occurred, or maybe this is just a non-SELECT statement */ ...
Get Managing & Using MySQL, 2nd Edition 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.