How to batch execute multiple statements in PHPmysqli
May 19, 2018 am 10:11 AMThis 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(); ?>
Related recommendations:
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!

Hot Article

Hot tools Tags

Hot Article

Hot Article Tags

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian

How To Set Up Visual Studio Code (VS Code) for PHP Development
