Tagged: $this- db- insert codeigniter

How to Get Codeigniter last inserted ID from database 0

Codeigniter last inserted ID

Today, We want to share with you Simple Way To Get Codeigniter last inserted ID.
In this post we will show you codeigniter get last insert id, hear for codeigniter get last record id we will give you demo and example for implement.In this post, we will learn about codeigniter get last insert id in controller with an example.

Codeigniter last inserted ID Example

function add_item(){
   $input = ['name'=>'Pakainfo', 'description'=>'This is Pakainfo'];

   $this->db->insert('products', $input);
   $insertId = $this->db->insert_id();

   return  $insertId;
}

As above simple example We can fetch simply codeigniter get last insert row id in controller using PHP Based “insert_id()” function, Therefor let’s simple use this Best way.

CodeIgniter last inserted ID

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

Read :

Summary

You can also read about AngularJS, ASP.NET, VueJs, PHP.

I hope you get an idea about how to get id from database in codeigniter.
I would like to have feedback on my Pakainfo.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.