int mysql_next_result(MYSQL *mysql)
mysql_next_result() is used
when you execute multiple statements specified as a single
statement string, or when you use
CALL statements to execute
stored procedures, which can return multiple result sets.
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, there are no more results.
Before each call to
mysql_next_result(), you must
the current statement if it is a statement that returned a
result set (rather than just a result status).
mysql_next_result() the state
of the connection is as if you had called
mysql_query() for the next
statement. This means that you can call
mysql_affected_rows(), and so
If your program uses
statements to execute stored procedures, the
CLIENT_MULTI_RESULTS flag must be enabled.
This is because each
returns a result to indicate the call status, in addition to
any result sets that might be returned by statements executed
within the procedure. Because
CALL can return multiple
results, process them using a loop that calls
determine whether there are more results.
CLIENT_MULTI_RESULTS can be enabled when
either explicitly by passing the
CLIENT_MULTI_RESULTS flag itself, or
implicitly by passing
CLIENT_MULTI_STATEMENTS (which also enables
CLIENT_MULTI_RESULTS). In MySQL
enabled by default.
It is also possible to test whether there are more results by
However, this function does not change the connection state,
so if it returns true, you must still call
mysql_next_result() to advance
to the next result.
For an example that shows how to use
Section 3.6.2, “Multiple Statement Execution Support”.
|0||Successful and there are more results|
|-1||Successful and there are no more results|
|>0||An error occurred|
Commands were executed in an improper order. For example, if you did not call
mysql_use_result()for a previous result set.
The MySQL server has gone away.
The connection to the server was lost during the query.
An unknown error occurred.