HOW TO GET LAST INSERTED ID FROM TABLE IN SQL IN CODEIGNITER

PHP
$id = $this->db->insert_id();   $this->db->insert('posts', $post_data);
   $insert_id = $this->db->insert_id();
   return  $insert_id;
Source

Also in PHP: