简体   繁体   中英

In codeigniter How i can check update?

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

but in that case, if user dose not changed before information that in db's Info, it does not update.

So always return 0;

I want check update's Successful or fail

How I can Check?

The best way is use transaction mechanism of codeigniter as below:

$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;
    }

像这样使用支票

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

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