检查update_batch()是否成功的笨(Check whether update_batch(

2019-06-24 02:51发布

我在笨运行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

这似乎是一个相当简单的事情从一个批处理更新功能要求。 是不是有什么我已经错过了,或者我应该只写我自己的批量更新的代码?

Answer 1:

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

希望这可以帮助!。 干杯!



Answer 2:

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

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


文章来源: Check whether update_batch() is successful in CodeIgniter