Mysqli multiple query features to implement multiple SQL statement query _mysql

Source: Internet
Author: User
Tags mysql tutorial

Mysqli compared to MySQL has a lot of advantages, recommend that you use, if you do not know, you can view the basics of MySQL tutorial:

MYSQLI Connection Database and mysqli preprocessing prepare used. Not only that, mysqli is more support for multiple query features, look at the following section of PHP code:

Copy Code code as follows:

<?php
$mysqli = new Mysqli ("localhost", "root", "" "," new ");
$mysqli->query ("Set names ' UTF8");
More than one SQL statement
$sql = "Select Id,name from ' user ';";
$sql. = "Select Id,mail from ' user '";
Echo $sql;
if ($mysqli->multi_query ($sql)) {//multi_query () executes one or more SQL statements
do{
if ($rs = $mysqli->store_result ()) {//store_result () method Gets the result of the first SQL statement query
while ($row = $rs->fetch_row ()) {
Var_dump ($row);
echo "<br>";
}
$rs->close (); Close result set
if ($mysqli->more_results ()) {//To determine if there are more result sets
echo "}
}
}while ($mysqli->next_result ());//next_result () method gets the next result set, returns a bool value
}
$mysqli->close (); To close a database connection
?>


With regard to some of the methods used, I have commented very clearly, especially to note that Multi_query () to execute multiple statements, between statements is used; Separated, otherwise there will be an error

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.