How to Get Last inserted ID in CodeIgnier?

We often need last inserted ID for different reasons(for example when you need to store foreign key), Immediately after a record has been inserted into the database, you can get the id that was auto incremented(primary Key).

Basic PHP MySQL Method

simply call CodeIgniter method

That’s it!

Reference URL:

I hope you like this Post, Please feel free to comment below, your suggestion and problems if you face - we are here to solve your problems.

0 0 votes
Article Rating
Notify of
Newest Most Voted
Inline Feedbacks
View all comments
Suresh Reddy Kunapally
Suresh Reddy Kunapally
7 years ago

Very good blog.

shubhra vashishtha
shubhra vashishtha
4 years ago

hey i want a code for auto increment the product code according to its caytegory in a shoping website ,there are multiple products and i will set a specific code for each product ,now i want to auto increment that product code according to category ,when i insert any products.for example my product code is nag001 ,nam002,nac003,for 3 different products.when i insert a product with the code nag001 so it will increment to nag002,can anyone help me plz Protection Status
Would love your thoughts, please comment.x