get last insert id after insert query in codeigniter active record

- get last insert id after insert query in codeigniter active record

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();
Please follow and like us:
0

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

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

Example:
For add data into table,

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

Here, $insert_id = $this->db->insert_id(); 
returns the last inserted Id.
Please follow and like us:
0