在codeigniter如何检查更新?

时间:2017-01-12 05:20:22

标签: php mysql codeigniter

if($this->db->affected_rows()>0){
            return TRUE;
        }else{
            return FALSE;
        }

但是在这种情况下,如果用户剂量没有在db的Info中的信息之前更改,则它不会更新。

所以总是返回0;

我希望检查更新成功或失败

我如何检查?

2 个答案:

答案 0 :(得分:1)

最好的方法是使用codeigniter的事务机制,如下所示:

$this->db->trans_begin();//begins your transaction
$data =<data> //data for upadating
$this->db->where('id', $id);//where condition
$this->db->update('table_name',$data);//update query

 if ($this->db->trans_status() === FALSE)//checks transaction status
    {
        $this->db->trans_rollback();//if update fails rollback and  return false
       return FALSE;

    }
    else
    {
        $this->db->trans_commit();//if success commit transaction and returns true
        return TRUE;
    }

答案 1 :(得分:0)

只需使用这样的支票

if($this->db->affected_rows()>=0){}