Codeigniter provides method insert_id () to get the last inserted id. insert_id () is function of "DB" library. DB library provides several functions for connecting database tasks. insert_id () will return the id of last inserted record. So here I give the controller method so you can understand how it is working.