Table of Contents
php+mysqli preprocessing technology realizes the method of adding, modifying and deleting multiple data, mysqli multiple
Home Backend Development PHP Tutorial PHP+mysqli preprocessing technology realizes the method of adding, modifying and deleting multiple data, mysqli multiple_PHP tutorial

PHP+mysqli preprocessing technology realizes the method of adding, modifying and deleting multiple data, mysqli multiple_PHP tutorial

Jul 13, 2016 am 10:08 AM
mysqli php Connect to the database preprocessing

php+mysqli preprocessing technology realizes the method of adding, modifying and deleting multiple data, mysqli multiple

The example in this article describes the method of adding, modifying and deleting multiple pieces of data using php+mysqli preprocessing technology. Share it with everyone for your reference. The specific analysis is as follows:

First of all, let’s talk about why we need preprocessing (precompilation) technology? For example: Suppose you want to add 100 users to the database. According to the conventional idea, 100 execution requests are sent to the database. At this time, according to the working principle of the mysql database, it needs to compile each execution statement (here are 100 Second-rate). Therefore, the efficiency here is very low.

The role of preprocessing (precompilation) technology is to reduce the number and time of compilation to improve the effect. Let’s use a case to illustrate how preprocessing (precompilation) technology is achieved (well, let’s make it clear first, when the php program sends the sql statement for the first time, the mysql database is compiled. After the next 99 times, php only needs to Just send the data there, no compilation is required).

<?php
//1、创建数据库连接对象
$mysqli = new MySQLi("localhost","root","123456","liuyan");
if($mysqli->connect_error){
 die($mysqli->connect_error);
}
$mysqli->query("set names 'GBK'");
//2、创建预编译对象
$sql = "insert into account(id,balance) values(?,?)";
//这里用 ? 来代替要插入的数据值
$stmt = $mysqli->prepare($sql);
//返回一个statement对象,对象中的方法见手册 MySQLi_STMT
//3、绑定参数(需要插入的数据),并执行
$id=null;//这里我数据库设置成了 primary key auto_increment
$balance=100.5;
$stmt->bind_param("id",$id,$balance);
//绑定参数,返回值为布尔值。"if"按顺序代表插入数据的数据类型
//这里$id为int,用i表示,$balance为float型,用d表示,具体见手册
$res = $stmt->execute();//执行语句,返回值为布尔类型
//4、判断是否执行成功
if(!$res){
 echo "数据插入失败,balance值为:".$balance;
}else{
 echo "成功";
}

/*
*****插入第二条数据
*/
//3、绑定参数(需要插入的数据),并执行
$id=null;//这里我数据库设置成了 primary key auto_increment
$balance=400.3;
$stmt->bind_param("id",$id,$balance);
//绑定参数,返回值为布尔值。"if"按顺序代表插入数据的数据类型
//这里$id为int,用i表示,$balance为float型,用d表示。
$res = $stmt->execute();//执行语句,返回值为布尔类型
//4、判断是否执行成功
if(!$res){
 echo "数据插入失败,balance值为:".$balance;
}else{
 echo "成功";
}
?>
Copy after login

I hope this article will be helpful to everyone’s PHP programming design.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/950895.htmlTechArticlephp+mysqli preprocessing technology to realize the method of adding, modifying and deleting multiple pieces of data, mysqli multiple pieces of data are described in this article Using php+mysqli preprocessing technology to add, modify and delete multiple pieces of data...
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