【发布时间】:2012-05-11 01:13:54
【问题描述】:
我正在 CodeIgniter 中的一个表上运行 update_batch(),我想检查它是否成功。
我尝试过使用affected_rows(),但它只计算被修改的表单字段的数量,所以它并没有完全减少它:
$this->db->update_batch("sections", $data, "alias");
log_message("debug", "items in form: ".count($data));
// items in form: 3
log_message("debug", "rows updated: ".$this->db->affected_rows());
// rows updated: 0-3
// depending on whether anything was actually changed on the form
return ($this->db->affected_rows() == count($data)); // unreliable
从批量更新功能中询问似乎是一件相当简单的事情。有什么我遗漏的还是我应该编写自己的批量更新代码?
【问题讨论】:
-
您是否可以选择使用事务而不是 CI 的
update_batch? -
我正在与 MyISAM 合作开展这个项目,因为它用于一个不会经常更新的简单 CMS。不过很好,我可能会考虑切换到 InnoDB。
标签: php codeigniter activerecord