Heim  >  Artikel  >  php教程  >  codeigniter 2.2 affected_rows()返回值不准确

codeigniter 2.2 affected_rows()返回值不准确

WBOY
WBOYOriginal
2016-06-06 20:13:451230Durchsuche

问题描述 今天在完成一个项目调用想要检验一下计划插入的数据是否都正常插入了。调用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();
}
Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn