Codeigniter Get Last Insert Id

Codeigniter get last insert id by Query : It is quite simple and easy to get the last inserted id in Codeigniter. $this->db->insert_id(); is used to get the last insert id in codeigniter. It returns the ID Number(primary key) of the last insert record in the table. Let us see how to get last inserted row from table.

Codeigniter get last insert id | Query | Last Inserted row Id Example

$this->db->insert_id(); gives the last inserted record’s id. Run this after insert query to get the last inserted id. Here is simple example of insert query and get last insert id.

Codeigniter get last insert id

Codeigniter get last inserted id

$data = array('name' => $name, 'email' => $email);

$this->db->insert_string('users', $data); 

$id = $this->db->insert_id(); // Will return the last insert id.

So you can use the above syntax to get last insert id after inserting any new record in database table.


Advertisements

Add Comment

📖 Read More