Use mysql_stmt_init() to create multiple statements. When one statement A completes its work (that is, fetches all result sets or no result sets) but is not closed, use statement B to query with result sets and succeed. Closing statement A at this point will cause the result set of statement B to disappear. The same problem will occur if statement B is replaced with mysql_query(). Attached is the demo code.