How to Get Codeigniter last inserted ID from database

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.


Related FAQ

Here are some more FAQ related to this Article:

  1.   Ajax Contact Form with Captcha reCAPTCHA v2/2.0 using PHP with jQuery
  2.   PHP – Loop Between Two Dates Example
  3.   PHP file_get_contents URL Examples
  4.   Laravel 5.7 Stripe Payment Gateway Example From Scratch
  5.   PHP Ajax Form Validation without page refresh
  6.   Laravel 5.8 Get Client IP Address Example
  7.   Google adsense Remove Yellow Background box in wordpress
  8.   php try catch Block Exception Handling
  9.   Event Directives with Parameters using Angular Example
  10.   Vue router Get Current URL in Vue.js Example