Get the id of the last updated record

后端 未结 6 1326
天涯浪人
天涯浪人 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:21

    $this->db->insert_id();  
    

    this will give only inserted id. For getting the updated row id you can add a column as lastmodified (timestamp) and update this column with current timestamp everytime you run the update query. After your update query just run this:

    $query = $this->db->query('SELECT id FROM StockMain ORDER BY lastmodified DESC LIMIT 1');  
    $result = $query->result_array();  
    

    You will get the id in the result set.

提交回复
热议问题