How to get last inserted id in CodeIgniter?

Member

by braeden , in category: Technology , 3 years ago

How to get last inserted id in CodeIgniter?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

by kade.hermiston , 3 years 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;
}