加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

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

发布时间:2020-12-13 17:11:54 所属栏目:PHP教程 来源:网络整理
导读:我在CodeIgniter中的表上运行update_batch(),我想检查它是否成功. 我尝试过使用affected_rows(),但这只计算了已经修改过的表单字段的数量,因此它并没有完全删除它: $this-db-update_batch("sections",$data,"alias");log_message("debug","items in form: "
我在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

从批量更新功能中询问这似乎是一件相当简单的事情.有没有我错过的东西或者我应该编写自己的批量更新代码?

解决方法

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

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读