Codeigniter 數據庫操做事務狀況下獲取不到last_insert_id()

開發中,數據庫Insert使用了事務,若是數據庫

$this->db->insert_id()

放在this

$this->db->trans_complete();

這句語句以後,$this->db->insert_id()會返回0,獲取不到值;code

在開啓事務的狀況下,要將$this->db->insert_id()放在$this->db->trans_complete();以前。事務

如:開發

$this->db->trans_start();
$this->db->insert('table',$data);
$id = $this->db->insert_id();
$this->db->trans_complete();
相關文章
相關標籤/搜索