You can call the mysql_stmt_next_result() function to return the next result in the result set of a prepared statement.
Syntax
int
mysql_stmt_next_result(MYSQL_STMT *mysql)
Return values
| Return value | Description |
|---|---|
| 0 | More results exist. |
| -1 | No more results exist. |
| >0 | An error occurred. |
Errors
CR_COMMANDS_OUT_OF_SYNC: Commands were executed in an improper order.CR_SERVER_GONE_ERROR: The connection to the OBServer was disconnected.CR_SERVER_LOST: The connection to the server was lost during the query.CR_UNKNOWN_ERROR: An unknown error occurred.
Notes
This function is used when you use prepared CALL statements to execute stored procedures, which can return multiple result sets. You can call mysql_stmt_next_result() in a loop to determine whether more results exist. If a procedure has OUT or INOUT arguments, their values will be returned as a single-row result set following other result sets. The values will appear in the order in which they are declared in the procedure parameter list.
mysql_stmt_next_result() returns a status to indicate whether more results exist. If mysql_stmt_next_result() returns an error, no more results exist.
Before each call to mysql_stmt_next_result(), you must call mysql_stmt_free_result() for the current statement returns a result set (rather than just a result status).
After calling mysql_stmt_next_result(), the status of the connection is the same as calling mysql_stmt_execute(). This means that you can call mysql_stmt_bind_result(), mysql_stmt_affected_rows(), and so on.
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 call mysql_stmt_next_result() to advance to the next result.