how to get last insert id after insert query in codeigniter active record

后端 未结 9 960
庸人自扰
庸人自扰 2020-11-28 01:59

I have an insert query (active record style) used to insert the form fields into a MySQL table. I want to get the last auto-incremented id for the insert operation as the re

9条回答
  •  温柔的废话
    2020-11-28 02:29

    Try this

    function add_post($post_data){
       $this->db->insert('posts', $post_data);
       $insert_id = $this->db->insert_id();
    
       return  $insert_id;
    }
    

    In case of multiple inserts you could use

    $this->db->trans_start();
    $this->db->trans_complete();
    

提交回复
热议问题