How to batch query data from multiple tables with php+mysqli, query multiple tables with phpmysqli
The example in this article describes the method of batch querying data from multiple tables using php+mysqli. Share it with everyone for your reference. The specific implementation method is as follows:
Note that two new functions multi_query and store_result are used here. The specific codes are as follows:
Copy code The code is as follows:
//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/949451.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/949451.htmlTechArticlephp+mysqli batch query method of multiple table data, phpmysqli query multiple tables The example of this article tells about php+mysqli batch How to query data from multiple tables. Share it with everyone for your reference. Specific actual...