Mysqli multi-query feature enables querying bitsCN.com with multiple SQL statements
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:
$ 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"
";
}
$ 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.
BitsCN.com