Get the id of the last updated record

后端 未结 6 1329
天涯浪人
天涯浪人 2021-01-23 02:51

I am able to get the last inserted id using $this->db->insert_id(); in codeigniter, is there any way that I can get the id of the last updated record? I tried

6条回答
  •  广开言路
    2021-01-23 03:18

    Using a codeigniter , and MY_MODEL an extend version.This was one of the bottlneck this how i got a relfe.

      function update_by($where = array(),$data=array())
      {
            $this->db->where($where);
            $query = $this->db->update($this->_table,$data);
            return $this->db->get($this->_table)->row()->id; //id must be exactly the name of your table primary key
      }
    

    call this Updates plus get the updated id. kinda overkill to run a query twice i guess but so do all the aboves.

    how you call ?

     $where = array('ABC_id'=>5,'DEF_ID'=>6);
     $data =  array('status'=>'ACCEPT','seen_status' =>'SEEN');
     $updated_id= $this->friends->update_by($where,$data);
    

提交回复
热议问题