How to get last inserted id in CodeIgniter?

Member

braeden

by braeden , in category: Technology , a month ago

How to get last inserted id in CodeIgniter?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

by kade.hermiston , a month ago

CodeIgniter DB Class insert_id() method is used to get last insert id.

Usage:

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