How do you get last insert id in codeigniter?

How do you get last insert id in codeigniter?

Team Leader Asked on February 12, 2018 in CODEIGNITER.
Add Comment
2 Answer(s)

    you can use $this->db->insert_id();

    
    public function insert_data($data)
    
    {
    
    $this->db->insert("table name",$data);
    
    $lastID = $this->db->insert_id();
    
    return $lastID;
    
    }
    
    
    Senior Developer Answered on February 12, 2017.
    Add Comment
      $this->db->insert_id(); //the last records from the table
      
      Senior Developer Answered on July 2, 2018.
      Add Comment

      Your Answer

      By posting your answer, you agree to the privacy policy and terms of service.