Share PHP How to implement mysqli batch execution of multiple statement instances

Source: Internet
Author: User
This article mainly introduces the PHP implementation of mysqli batch execution of multiple statements, combined with an example of the PHP connection mysqli and batch execution of multiple statements related operation skills, the need for friends can refer to the next

In this paper, we describe how PHP implements mysqli batch execution of multiple statements. Share to everyone for your reference, as follows:

You can perform multiple operations at once or retrieve multiple result sets.

Instance:


<?php$mysqli = new mysqli ("localhost", "root", "111111", "test");/* check  Connection */if (Mysqli_connect_errno ()) {printf ("Connect failed:%s\n", Mysqli_connect_error ()); Exit ();} /* Multi_query executes one or more queries against the database. Multiple queries are delimited by semicolons. */$query = "SELECT * from Test where id = 1;"; $query. = "SELECT name from Test";/* executes the query in bulk and returns FALSE if the first query fails.  */if ($mysqli->multi_query ($query)) {do {/*) gets the first result set */if ($result = $mysqli->store_result ()) {while ($row = $result->fetch_row ())      {printf ("%s\n", $row [0]);    } $result->free ();    }/* Check if a multi-query has more results */if ($mysqli->more_results ()) {printf ("-----------------\ n"); }//Prepare the next result set} while ($mysqli->next_result ());} /* Close connection */$mysqli->close ();? 

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.