This article illustrates the method of Php+mysqli batch querying multiple table data. Share to everyone for your reference. The implementation methods are as follows:
Note that two new functions multi_query and Store_result are used here, and the specific code is as follows:
Copy Code code as follows:
<?php
1. Create DATABASE Connection objects
$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 (), this returns a Boolean value
do{
$result = $mysqli->store_result ();//This will actually return the resource object of the result set, and return False if it fails;
while ($row = $result->fetch_assoc ()) {
foreach ($row as $key => $value) {
echo "--$value--";
}
echo "}
$result->free ();
if ($mysqli->more_results ()) {//To determine if there is a result set
echo "----------Query the data for the next table---------------<br>";
}
}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 your PHP program design.