Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get a value from the last inserted row using Codeigniter

Tags:

codeigniter

Is there any codeigniter function to do this?

like image 356
Hasnain Avatar asked Jan 21 '13 06:01

Hasnain


People also ask

How to fetch last inserted id in CodeIgniter?

Well, lucky for you.... getting the last database inserted ID using CodeIgniter is very simple. All you need to do is call the $this->db->insert_id(); function after you have just finished inserting a new row into the database and this will return that last 'unique' ID.

How do you get the last inserted record in CI?

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.

How to get last inserted id in CodeIgniter 4?

CodeIgniter 4 Query Builder insertID()Using the Query Builder Class, we can INSERT and retrieve the Last Insert ID value, leveraging the built-in $builder insertID() method, which is called on the $db connection instance. Again, visiting the URL, /cicrud/home/users, executes the users() Home Controller method.

How do you find the last inserted value?

If you are AUTO_INCREMENT with column, then you can use last_insert_id() method. This method gets the ID of the last inserted record in MySQL.


1 Answers

try this code:

$this->db->insert_id();

Refer: https://www.codeigniter.com/user_guide/database/helpers.html

like image 183
Mani Avatar answered Oct 22 '22 05:10

Mani