Table of Contents
Related recommendations:
Home Backend Development PHP Tutorial How to batch execute multiple statements in PHPmysqli

How to batch execute multiple statements in PHPmysqli

May 19, 2018 am 10:11 AM
php statement

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

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

php mysqli implements batch execution of insert, update and delete data methods, 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!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian Dec 24, 2024 pm 04:42 PM

PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian

CakePHP Date and Time CakePHP Date and Time Sep 10, 2024 pm 05:27 PM

CakePHP Date and Time

CakePHP Project Configuration CakePHP Project Configuration Sep 10, 2024 pm 05:25 PM

CakePHP Project Configuration

CakePHP File upload CakePHP File upload Sep 10, 2024 pm 05:27 PM

CakePHP File upload

CakePHP Routing CakePHP Routing Sep 10, 2024 pm 05:25 PM

CakePHP Routing

Discuss CakePHP Discuss CakePHP Sep 10, 2024 pm 05:28 PM

Discuss CakePHP

CakePHP Quick Guide CakePHP Quick Guide Sep 10, 2024 pm 05:27 PM

CakePHP Quick Guide

How To Set Up Visual Studio Code (VS Code) for PHP Development How To Set Up Visual Studio Code (VS Code) for PHP Development Dec 20, 2024 am 11:31 AM

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

See all articles