You can call the mysql_next_result() function to execute multiple statements as a single statement string, or use CALL statements to execute stored procedures, which can return multiple result sets.
Syntax
int
mysql_next_result(MYSQL *mysql)
Return values
| Return value | Description |
|---|---|
| 0 | More results exist. |
| -1 | No more results exist. |
| >0 | An error occurred. |
Notes
mysql_next_result() reads the next statement result and returns a status to indicate whether more results exist. If mysql_next_result() returns an error, no more results exist. Before each call to mysql_next_result(), you must call mysql_free_result() for the current statement if it is a statement that returns a result set (rather than just a result status). After mysql_next_result() is called, the state of the connection is as if mysql_real_query() or mysql_query() has been called for the next statement. This means that you can call mysql_store_result(), mysql_warning_count(), mysql_affected_rows() and so on. If the program uses CALL statements to execute stored procedures, the CLIENT_MULTI_RESULTS flag must be enabled. This is because each CALL statement returns a result to indicate the call status, in addition to the result sets that might be returned by statements executed within the procedure. Because CALL can return multiple results, call mysql_next_result() in a loop manner to determine whether more results exist. You can also call mysql_more_results() to test whether more results exist. However, this function does not change the connection status. If it returns TRUE, you must still call mysql_next_result() to advance to the next result.