Php+mysqli How to query multiple table data in bulk _php tutorial

Source: Internet
Author: User
Tags php programming

Php+mysqli method of batch querying multiple table data


This article mainly introduces the method of Php+mysqli batch query multiple table data, involving the use of Multi_query, Store_result and More_results functions, the need for friends can refer to the following

This paper describes the method of Php+mysqli batch querying multiple table data. Share to everyone for your reference. The implementation method is as follows:

Note that two new functions multi_query and Store_result are used here, with the following code:

The code is as follows:

1. Create a database Connection object
$mysqli = new Mysqli ("localhost", "root", "123456", "Liuyan");
if ($mysqli->connect_error) {
Die ($mysqli->connect_error);
}
$mysqli->query ("Set names ' GBK '");
2. Querying 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 (), this returns a Boolean value
do{
$result = $mysqli->store_result ();//The resource object of the result set is actually returned here, and the failure returns false;
while ($row = $result->fetch_assoc ()) {
foreach ($row as $key = = $value) {
echo "--$value--";
}
echo "";
}
$result->free ();
if ($mysqli->more_results ()) {//determine if a result set is still present
echo "----------Query the data for the next table---------------
";
}
}while ($mysqli->next_result ());//next_result () returns TRUE or false;
}
4. Close the database connection
$mysqli->close ();
?>

I hope this article is helpful to everyone's PHP programming.

http://www.bkjia.com/PHPjc/950761.html www.bkjia.com true http://www.bkjia.com/PHPjc/950761.html techarticle php+mysqli How to query multiple table data in bulk this article mainly introduces the method of Php+mysqli batch query multiple table data, involving Multi_query, Store_result and More_results ...

  • 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.