Php+mysqli method of batch querying multiple table data
This article mainly introduces the method of Php+mysqli batch query multiple table data, involving the use of Multi_query, Store_result and More_results functions, the need for friends can refer to the following
This paper describes the method of Php+mysqli batch querying multiple table data. Share to everyone for your reference. The implementation method is as follows:
Note that two new functions multi_query and Store_result are used here, with the following code:
The code is as follows:
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. Querying multiple database tables
$SQLS = "SELECT * FROM News limit 10, 4;";
$sqls. = "SELECT * from user;";
3. Execute and process the results
if ($res = $mysqli->multi_query ($sqls)) {
Note: Unlike $mysqli->query (), this returns a Boolean value
do{
$result = $mysqli->store_result ();//The resource object of the result set is actually returned here, and the failure returns false;
while ($row = $result->fetch_assoc ()) {
foreach ($row as $key = = $value) {
echo "--$value--";
}
echo "";
}
$result->free ();
if ($mysqli->more_results ()) {//determine if a result set is still present
echo "----------Query the data for the next table---------------
";
}
}while ($mysqli->next_result ());//next_result () returns TRUE or false;
}
4. Close the database connection
$mysqli->close ();
?>
I hope this article is helpful to everyone's PHP programming.
http://www.bkjia.com/PHPjc/950761.html www.bkjia.com true http://www.bkjia.com/PHPjc/950761.html techarticle php+mysqli How to query multiple table data in bulk this article mainly introduces the method of Php+mysqli batch query multiple table data, involving Multi_query, Store_result and More_results ...