How to batch query data from multiple tables with php+mysqli_PHP tutorial

WBOY
Release: 2016-07-13 10:08:35
Original
921 people have browsed it

How to batch query data from multiple tables with php+mysqli

This article mainly introduces the method of batch querying data from multiple tables with php+mysqli, involving multi_query, For tips on using functions such as store_result and more_results, friends in need can refer to

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:

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.

www.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...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template