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 ();?