On this article, I want to share how to get last id have been inserted into database.

$data = array(
               'field_1' => 'Hello' ,
               'field_2' => 'Bro..!' ,
            );

$this->db->insert('table', $data); 

//Below is code to get last ID inserted
$last_id = $this->db->insert_id();