获取上次更新记录的ID

Kam*_*med 2 php activerecord codeigniter codeigniter-2

我能够$this->db->insert_id();在codeigniter中使用最后一个插入的id ,是否有任何方法可以获取最后更新记录的id?我用相同的尝试它,$this->db->insert_id();但它不起作用(返回0代替).

Kam*_*med 6

Codeigniter不支持这一点.我不得不这样做:

$updated_id = 0;

// get the record that you want to update
$this->db->where(array('vrnoa'=>$data['vrnoa'], 'etype' => 'sale'));
$query = $this->db->get('StockMain');

// getting the Id
$result = $query->result_array();
$updated_id = $result[0]['stid'];

// updating the record
$this->db->where(array('vrnoa'=>$data['vrnoa'], 'etype' => 'sale'));
$this->db->update('StockMain',$data);
Run Code Online (Sandbox Code Playgroud)