how to get last insert id after insert query in codeigniter active record
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();
A transaction isn't needed here, this should suffice:
function add_post($post_data) { $this->db->insert('posts',$post_data); return $this->db->insert_id();}