//1. Create 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 results
if($res = $mysqli->multi_query($sqls)){
//Note: Unlike $mysqli->query(), what is returned here is a Boolean value
do{
$result = $mysqli->store_result();//This is where the resource object of the result set is actually returned. If it fails, false is returned;
while($row = $result->fetch_assoc()){
foreach($row as $key=>$value){
echo "--$value--";
}
echo "
";
}
$result->free();
if($mysqli->more_results()){//Determine whether there is still a result set
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 be helpful to everyone’s PHP programming design.
http://www.bkjia.com/PHPjc/950761.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/950761.htmlTechArticleHow to batch query multiple table data with php+mysqli This article mainly introduces the method of batch querying multiple tables with php+mysqli The method of table data involves the use of functions such as multi_query, store_result and more_results...