简体   繁体   中英

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.

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:

$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");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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