codeigniter insert id code example

Example 1: return last insert id in codeigniter

$id = $this->db->insert_id();

Example 2: 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;
}

Example 3: codeigniter return last inserted id

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

Example 4: codeigniter last insert id

$last_inserted_id = $this->db->insert_id();

Example 5: how to get last id in database codeigniter 4

$db = db_connect();
  $query = $db->query("SELECT * FROM users ORDER BY id DESC LIMIT 1");
  $result = $query->getRow();

Tags:

Php Example