last insert id model codeigniter 1

last insert id model codeigniter

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

   return  $insert_id;
}

Here is what the above code is Doing:
1. We are using the insert() method of the database library to insert the data into the posts table.
2. We are using the insert_id() method of the database library to get the ID of the last inserted record.
3. We are returning the ID of the last inserted record.

Similar Posts