How to get last insert ID in PHP Codeigniter?

In this article, we are going to discuss how to get the last inserted ID in Codeigniter. I will let you know how to get the last inserted id from the table. Sometimes, You have to work on relational tables where you perform the insert query on a table and you need that automatically generated ID to insert into the second table to create a relation between both tables.

In PHP, you can use the mysqli_insert_id function to get the last inserted ID.

In Codeigniter, You can use $this->db->insert_id(); function to get the last inserted ID.

insert_id() is function of "db" library. There is a number of query helper methods in Codeigniter.

function saveUserInfo(){
   $input = ['name'=>'blazing coders', 'email'=>''];
   $this->db->insert('users', $input);
   $insertId = $this->db->insert_id();
   return  $insertId;

Related Posts

Payroll Management Software

Blazingcoders offering Payroll Management Software that help our clients in preparing salary and wag

Hire Software, Mobile And Automation Tester Mumbai

Blazingcoders in Mumbai the Manchester city of India, provides a wide range of service in Software t

How to Send Email in Laravel using SMTP

Today we are going to explain how to send email in Laravel using STMP. Laravel is PHP based fra