10bet网址
MySQL 5.7 C API Developer Guide
Download this Manual

5.4.77 mysql_store_result()

MYSQL_RES * mysql_store_result(MYSQL *mysql)

Description

After invokingmysql_query()ormysql_real_query(), you must callmysql_store_result()ormysql_use_result()for every statement that successfully produces a result set (SELECT,SHOW,DESCRIBE,EXPLAIN,CHECK TABLE, and so forth). You must also callmysql_free_result()after you are done with the result set.

You need not callmysql_store_result()ormysql_use_result()for other statements, but it does not do any harm or cause any notable performance degradation if you callmysql_store_result()in all cases. You can detect whether the statement has a result set by checking whethermysql_store_result()returns a nonzero value (more about this later).

If you enable multiple-statement support, you should retrieve results from calls tomysql_query()ormysql_real_query()by using a loop that callsmysql_next_result()to determine whether there are more results. For an example, seeSection 3.6.2, “Multiple Statement Execution Support”.

To determine whether a statement returns a result set, callmysql_field_count(). SeeSection 5.4.22, “mysql_field_count()”.

mysql_store_result()reads the entire result of a query to the client, allocates aMYSQL_RESstructure, and places the result into this structure.

mysql_store_result()returnsNULLif the statement did not return a result set (for example, if it was anINSERTstatement), or an error occurred and reading of the result set failed.

An empty result set is returned if there are no rows returned. (An empty result set differs from a null pointer as a return value.)

After you have calledmysql_store_result()and gotten back a result that is not a null pointer, you can callmysql_num_rows()to find out how many rows are in the result set.

You can callmysql_fetch_row()to fetch rows from the result set, ormysql_row_seek()andmysql_row_tell()to obtain or set the current row position within the result set.

SeeSection 3.6.7, “NULL mysql_store_result() Return After mysql_query() Success”.

Return Values

A pointer to aMYSQL_RESresult structure with the results.NULLif the statement did not return a result set or an error occurred. To determine whether an error occurred, check whethermysql_error()returns a nonempty string,mysql_errno ()returns nonzero, ormysql_field_count()returns zero.

Errors

mysql_store_result()resetsmysql_error()andmysql_errno ()if it succeeds.