Generally, MySQL does not allow execution of multiple statements at a time for security reasons (but no error is reported, which is depressing ).
Generally, MySQL does not allow execution of multiple statements at a time for security reasons (but no error is reported, which is depressing ).
MySQL allows you to specify multiple statements for execution in a single query string by specifying parameters for the link:
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:
The 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:
The code is as follows:
Do
{
Result = mysql_store_result (mysql );
Mysql_free_result (result );
} While (! Mysql_next_result (mysql ));