MySQL allows you to specify multiple statements for execution in a single query string by specifying parameters for the link:
CopyCode The Code is as follows: // set when linking
Mysql_real_connect (..., client_multi_statements );
// Or
// Specify midway through
Mysql_set_server_option (MySQL, mysql_option_multi_statements_on); // MySQL is the connection name.
When using the multi-statement execution function, you must read the entire resault set; otherwise, an error occurs: commands out of sync; you can't run this command now
The officially recommended execution statement is as follows:Copy codeThe Code is as follows: do
{
/* Process all results */
...
Printf ("total affected rows: % LLD", mysql_affected_rows (MySQL ));
...
If (! (Result mysql_store_result (MySQL )))
{
Printf (stderr, "Got fatal error processing QUERY \ n ");
Exit (1 );
}
Process_result_set (result);/* client function */
Mysql_free_result (result );
} While (! Mysql_next_result (MySQL ));
If you just insert an SQL statement that does not need to return a value, you have to read the entire resault set and release it. The minimal syntax is as follows:Copy codeThe Code is as follows: do
{
Result = mysql_store_result (MySQL );
Mysql_free_result (result );
} While (! Mysql_next_result (MySQL ));