How to get last inserted id in Codeigniter?By Hardik Savani | February 28, 2017 | | 2155 Viewer | Category : MySql Codeigniter
Share this post:
Sometimes, we require to get last insert record id from database in controller, so in this example we will learn how to get last inserted row id in Codeigniter 3 project.
It's very often need to get last insert id in programming field, if you are working on Codeigniter framework and you want to fetch last created id, i mean max id, then you do easily.Codeigniter provide method insert_id() to get last inserted id.
insert_id() is function of "db" library. db library provides several function for connecting database task. insert_id() will return id of last inserted record. So here i give controller method so you can understand how it is working.
$input = ['name'=>'Test', 'description'=>'This is Test'];
$insertId = $this->db->insert_id();
As above example you can get simply last inserted row id using "insert_id()", So let's use this way.
I hope it can help you...
- Codeigniter 3 - Generate PDF from view using dompdf library with example
- Codeigniter 3 - CRUD(Create, Read, Update and Delete) using JQuery Ajax, Bootstrap, Models and MySQL
- Codeigniter 3 - select2 ajax autocomplete from database example with demo
- How to get last inserted id in laravel 5?
- How to get last executed mysql query in laravel ?
- How to confige Elasticsearch in our local system
- How to implement flash messages in PHP Codeigniter?
- Bootstrap SweetAlert - Confirm dialog box model with yes and no option example
- Twitter typeahead press enter key go to search page.
- Solve - no connection could be made target machine actively refused it laravel
- How to get year, month and day from timestamp date using carbon in Laravel 5?
- How to get last executed query in Larave 5?
- How to resolve - No supported encrypter found. The cipher and / or key length are invalid. in Laravel 5