search
HomeBackend DevelopmentPHP Tutorialphp+mysqli implements batch execution of insert, update and delete data methods, phpmysqli_PHP tutorial

php+mysqli realizes the method of inserting, updating and deleting data in batches, phpmysqli

The example in this article describes the method of inserting, updating and deleting data in batches using php+mysqli. Share it with everyone for your reference. The details are as follows:

mysqli executes insert/update/delete data in batches, the function is multi_query().

The following code only inserts data in batches. In fact, inserting data, updating data, deleting data, etc. can be mixed and executed together. This function is used when querying. Reading data is a little different. Please refer to the following code for details:

<&#63;php
//1、创建数据库连接对象
$mysqli = new MySQLi("localhost","root","123456","liuyan");
if($mysqli->connect_error){
 die($mysqli->connect_error);
}
$mysqli->query("set names 'GBK'");
//2、数据插入语句
$sqls = "insert into news(title,contents,datetime,hit) values('去哪儿网架构调整铺垫上市','据接近去哪儿网的消息人士透露,事业部以运营、收入、利润进行考核;新业务部则是以产品运营、商业模式、总亏损进行考核。','".date('Y-m-d H:i:s')."',30);";
$sqls .= "insert into news(title,contents,datetime,hit) values('告诉金主 视频网站谁是NO.1','搜狐说,自己稳稳超过土豆,是行业老二;腾讯说,自己已经超过了优酷,成为行业第一;土豆不承认腾讯的计算方法,坚称自己仍然是亚军;爱奇艺则摆出数据称在单用户观看时长方面排名第一位。','".date('Y-m-d H:i:s')."',30);";
$sqls .= "insert into news(title,contents,datetime,hit) values('苹果正滋生傲慢情绪','据国外媒体报道,没有经历重大挫折的成功往往会让人滋生傲慢。在过去10年中,苹果取得了巨大的成功,成为了音乐播放器和手机市场上的领导者,但却没未遭遇任何较大的挫折。','".date('Y-m-d H:i:s')."',30);";
//3、执行,注意批量执行函数
$res = $mysqli->multi_query($sqls);//返回的是布尔值
//4、判断是否执行成功
if(!$res){
 echo "数据插入失败";
}else{
 echo "成功!!!";
}
//5、关闭连接
$mysqli->close();
&#63;>

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

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/949452.htmlTechArticlephp+mysqli implements the method of inserting, updating and deleting data in batches, phpmysqli This article describes the php+mysqli implementation Method to perform insert, update and delete data in batches. Share with everyone...
Statement
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
How do you create and use an interface in PHP?How do you create and use an interface in PHP?Apr 30, 2025 pm 03:40 PM

The article explains how to create, implement, and use interfaces in PHP, focusing on their benefits for code organization and maintainability.

What is the difference between crypt() and password_hash()?What is the difference between crypt() and password_hash()?Apr 30, 2025 pm 03:39 PM

The article discusses the differences between crypt() and password_hash() in PHP for password hashing, focusing on their implementation, security, and suitability for modern web applications.

How can you prevent Cross-Site Scripting (XSS) in PHP?How can you prevent Cross-Site Scripting (XSS) in PHP?Apr 30, 2025 pm 03:38 PM

Article discusses preventing Cross-Site Scripting (XSS) in PHP through input validation, output encoding, and using tools like OWASP ESAPI and HTML Purifier.

What is autoloading in PHP?What is autoloading in PHP?Apr 30, 2025 pm 03:37 PM

Autoloading in PHP automatically loads class files when needed, improving performance by reducing memory use and enhancing code organization. Best practices include using PSR-4 and organizing code effectively.

What are PHP streams?What are PHP streams?Apr 30, 2025 pm 03:36 PM

PHP streams unify handling of resources like files, network sockets, and compression formats via a consistent API, abstracting complexity and enhancing code flexibility and efficiency.

What is the maximum size of a file that can be uploaded using PHP ?What is the maximum size of a file that can be uploaded using PHP ?Apr 30, 2025 pm 03:35 PM

The article discusses managing file upload sizes in PHP, focusing on the default limit of 2MB and how to increase it by modifying php.ini settings.

What is Nullable types in PHP ?What is Nullable types in PHP ?Apr 30, 2025 pm 03:34 PM

The article discusses nullable types in PHP, introduced in PHP 7.1, allowing variables or parameters to be either a specified type or null. It highlights benefits like improved readability, type safety, and explicit intent, and explains how to declar

What is the difference between the unset() and unlink() functions ?What is the difference between the unset() and unlink() functions ?Apr 30, 2025 pm 03:33 PM

The article discusses the differences between unset() and unlink() functions in programming, focusing on their purposes and use cases. Unset() removes variables from memory, while unlink() deletes files from the filesystem. Both are crucial for effec

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.