Home > Article > Backend Development > How to batch execute multiple statements in PHPmysqli
This article mainly introduces the method of PHP to implement mysqli to execute multiple statements in batches. It analyzes the related operation skills of PHP to connect to mysqli and execute multiple statements in batches in the form of examples. Friends in need can refer to the following
The details are as follows:
You can perform multiple operations or retrieve multiple result sets at one time.
Example:
<?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执行一个或多个针对数据库的查询。多个查询用分号进行分隔。 */ $query = "SELECT * from test where id = 1;"; $query .= "SELECT name FROM test"; /* 批量执行查询 ,如果第一个查询失败则返回 FALSE。*/ if ($mysqli->multi_query($query)) { do { /* 获取第一个结果集 */ if ($result = $mysqli->store_result()) { while ($row = $result->fetch_row()) { printf("%s\n", $row[0]); } $result->free(); } /* 检查一个多查询是否有更多的结果 */ if ($mysqli->more_results()) { printf("-----------------\n"); } //准备下一个结果集 } while ($mysqli->next_result()); } /* close connection */ $mysqli->close(); ?>
php mysqli batch query Methods for querying multiple tables of data using phpmysqli_PHP Tutorial
php mysqli Methods for inserting, updating and deleting data in batches, phpmysqli_PHP Tutorial
The above is the detailed content of How to batch execute multiple statements in PHPmysqli. For more information, please follow other related articles on the PHP Chinese website!