Name

mysql_use_result —

Synopsis

MYSQL_RES *mysql_use_result(MYSQL *mysql)

Reads the result of a query row by row and allows access to the data through a MYSQL_RES structure. Either this function or mysql_store_result must be called to access return information from a query. Because this function does not read the entire data set all at once, it is faster and more memory efficient than mysql_store_result. However, when using this function, you must read all the rows of the data set from the server or else the next query will receive the leftover data. Also, you cannot run any other queries until you are done with the data in this query. Even worse, no other threads running on the server can access the tables used by the query until you are finished. For this reason, you should use this function only when you are certain you can read the data in a timely manner and release it. 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 still returns a valid (but empty) MYSQL_RES structure; i.e., it does not return a null pointer.

Example

MYSQL_RES results;
mysql_query(&mysql, "SELECT * FROM people");
results = mysql_store_result(&mysql);
/* 'results' will now allow access (using mysql_fetch_row) to the table
   data, one row at a time */
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset