Mysqli has many advantages over mysql. We recommend that you use it. If you do not know it, you can view the basic mysql Tutorial:
Use mysqli to connect to the database and use mysqli preprocessing prepare. In addition, mysqli supports the multi-query feature. refer to the following php code:
Copy codeThe Code is as follows:
<? Php
$ Mysqli = new mysqli ("localhost", "root", "", "new ");
$ Mysqli-> query ("set names 'utf8 ");
// Multiple SQL statements
$ SQL = "select id, name from 'user ';";
$ SQL. = "select id, mail from 'user '";
Echo $ SQL;
If ($ mysqli-> multi_query ($ SQL) {// multi_query () executes one or more SQL statements
Do {
If ($ rs = $ mysqli-> store_result () {// store_result () method to obtain the query result of the first SQL statement
While ($ row = $ rs-> fetch_row ()){
Var_dump ($ row );
Echo "<br> ";
}
$ Rs-> Close (); // Close the result set.
If ($ mysqli-> more_results () {// determine whether there are more result sets
Echo "}
}
} While ($ mysqli-> next_result (); // obtain the next result set using the next_result () method, and return the bool value.
}
$ Mysqli-> close (); // close the database connection
?>
I have already commented out some of the methods used. Note that when multi_query () executes multiple statements, they are separated by commas (,). Otherwise, errors may occur.