简体   繁体   English

检查update_batch()是否在CodeIgniter中成功

[英]Check whether update_batch() is successful in CodeIgniter

I'm running update_batch() on a table in CodeIgniter and I'd like to check whether it was successful. 我在CodeIgniter中的表上运行update_batch(),我想检查它是否成功。

I've tried using affected_rows(), but that only counts the number of form fields that have been modified so it doesn't quite cut it: 我尝试过使用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

It seems like a fairly straightforward thing to ask from a batch update function. 从批量更新功能中询问这似乎是一件相当简单的事情。 Is there something I've missed or should I just write my own batch update code? 有没有我错过的东西或者我应该编写自己的批量更新代码?

    $this->db->trans_start();
    $this->db->update_batch($table, $update, $variable);
    $this->db->trans_complete();        
    return ($this->db->trans_status() === FALSE)? FALSE:TRUE;

Hope this helps!. 希望这可以帮助!。 Cheers! 干杯!

使用简单的指令,这将返回true或false

return $this->db->update_batch("sections", $data, "alias");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM