This article describes how to query data in multiple tables in batches using php + mysqli, and describes how to use functions such as multi_query, store_result, and more_results, for more information about how to query multiple tables in batches using php + mysqli, see the following example. Share it with you for your reference. The specific implementation method is as follows:
Note that two new functions multi_query and store_result are used. the code is as follows:
The code is as follows:
<? Php
// 1. create a database connection object
$ Mysqli = new MySQLi ("localhost", "root", "123456", "liuyan ");
If ($ mysqli-> connect_error ){
Die ($ mysqli-> connect_error );
}
$ Mysqli-> query ("set names 'gbk '");
// 2. query multiple database tables
$ Sqls = "select * from news limit 10, 4 ;";
$ Sqls. = "select * from user ;";
// 3. execute and process the result
If ($ res = $ mysqli-> multi_query ($ sqls )){
// Note: Unlike $ mysqli-> query (), a Boolean value is returned.
Do {
$ Result = $ mysqli-> store_result (); // The resource object of the result set is actually returned here. if the result fails, false is returned;
While ($ row = $ result-> fetch_assoc ()){
Foreach ($ row as $ key => $ value ){
Echo "-- $ value --";
}
Echo "";
}
$ Result-> free ();
If ($ mysqli-> more_results () {// You can check whether a result set exists.
Echo "---------- query the data of the next table ---------------
";
}
} While ($ mysqli-> next_result (); // next_result () returns true or false;
}
// 4. close the database connection
$ Mysqli-> close ();
?>
I hope this article will help you with php programming.