问题描述 今天在完成一个项目调用想要检验一下计划插入的数据是否都正常插入了。调用insert_batch()方法插入一百多条数据的时候发现affected_rows()返回值不准确。 问题分析 1.第一步打印last_query()发现插入的数据和affected_rows()数值确实是一样的 2.检
问题描述
今天在完成一个项目调用想要检验一下计划插入的数据是否都正常插入了。调用insert_batch()方法插入一百多条数据的时候发现affected_rows()返回值不准确。
问题分析
1.第一步打印last_query()发现插入的数据和affected_rows()数值确实是一样的
2.检查数据库,发现需要插入的一百多条数据也确实正常插入了
3.查看了一下代码,才知道在insert_batch()和update_batch()的时候,如果数据量大于100条,将会分多次插入,每次最多只会插入一百条。
详见下面的代码
// Batch this baby for ($i = 0, $total = count($this->ar_set); $i _update_batch($this->_protect_identifiers($table, TRUE, NULL, FALSE), array_slice($this->ar_set, $i, 100), $this->_protect_identifiers($index), $this->ar_where); $this->query($sql); }
影响范围
insert_batch(),update_batch()
解决方案
对插入的数据进行求余然后和affected_rows()进行对比检验插入数据是否正确
github上官方已经修复了这个问题
// Batch this baby $affected_rows = 0; for ($i = 0, $total = count($this->qb_set); $i query($this->_insert_batch($this->protect_identifiers($table, TRUE, NULL, FALSE), $this->qb_keys, array_slice($this->qb_set, $i, 100))); $affected_rows += $this->affected_rows(); }
原文地址:codeigniter 2.2 affected_rows()返回值不准确, 感谢原作者分享。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

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

Hot Article

Hot Tools

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.

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

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.

SublimeText3 Linux new version
SublimeText3 Linux latest version
