The world's most popular open source database
int mysql_next_result(MYSQL *mysql)
Description
This function is used when you execute multiple statements
specified as a single statement string, or when you execute
CALL statements, which can return
multiple result sets.
If more statement results exist,
mysql_next_result() reads the
next statement result and returns the status back to the
application.
Before calling
mysql_next_result(), you must
call mysql_free_result() for the
preceding statement if it is a query that returned a result set.
After calling
mysql_next_result() the state of
the connection is as if you had called
mysql_real_query() or
mysql_query() for the next
statement. This means that you can call
mysql_store_result(),
mysql_warning_count(),
mysql_affected_rows(), and so
forth.
If mysql_next_result() returns
an error, no other statements are executed and there are no more
results to fetch.
If your program executes stored procedures with the
CALL SQL statement, you
must set the
CLIENT_MULTI_RESULTS flag explicitly, or
implicitly by setting CLIENT_MULTI_STATEMENTS
when you call
mysql_real_connect(). This is
because each CALL returns a
result to indicate the call status, in addition to any results
sets that might be returned by statements executed within the
procedure. In addition, because
CALL can return multiple results,
you should process those results using a loop that calls
mysql_next_result() to determine
whether there are more results.
For an example that shows how to use
mysql_next_result(), see
Section 20.8.9, “C API Handling of Multiple Statement Execution”.
Return Values
| Return Value | Description |
| 0 | Successful and there are more results |
| -1 | Successful and there are no more results |
| >0 | An error occurred |
Errors
CR_COMMANDS_OUT_OF_SYNC
Commands were executed in an improper order. For example if
you didn't call
mysql_use_result() for a
previous result set.
CR_SERVER_GONE_ERROR
The MySQL server has gone away.
CR_SERVER_LOST
The connection to the server was lost during the query.
CR_UNKNOWN_ERROR
An unknown error occurred.


User Comments
Add your own comment.