Php+mysqli method of batch querying multiple table data _php skills

Source: Internet
Author: User
Tags create database

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.