Call Now

WhatsApp

Go back
to top

Arrow Icon
Site Logo

How to get last insert ID in PHP Codeigniter?

Shape Image Layout Star Icon Star Icon

How to get last insert ID in PHP Codeigniter?

In this article, we are going to discuss how to get the last inserted ID in Codeigniter. I will let you know how to get the last inserted id from the table. Sometimes, You have to work on relational tables where you perform the insert query on a table and you need that automatically generated ID to insert into the second table to create a relation between both tables.

In PHP, you can use the mysqli_insert_id function to get the last inserted ID.

In Codeigniter, You can use $this->db->insert_id(); function to get the last inserted ID.

insert_id() is function of "db" library. There is a number of query helper methods in Codeigniter.

function saveUserInfo(){
   $input = ['name'=>'blazing coders', 'email'=>'info.blazingcoders@gmail.com'];
   $this->db->insert('users', $input);
   $insertId = $this->db->insert_id();
   return  $insertId;
}

Tags :

How to get last insert id in Codeigniter controller

Get last row id in Codeigniter

How to get last inserted record in Codeigniter

Last insert id in Codeigniter 4
How to insert id from one table to another in Codeigniter

Codeigniter get next auto-increment id

How to get last updated id in Codeigniter

Codeigniter get next id

PHP MySQL last insert id how to get last inserted id in PHP Codeigniter
Mysql select last insert id from the table

How to get the last record in MySQL using PHP

How to get last inserted id in SQL

How to get last inserted record in MySQL

How to get last updated record id in PHP
Pdo last insert id returns 0

Related Posts

How to get the last insert ID in Codeigniter, How to get the last insert ID in PHP

How to read or detect text from image using Google Vision API

In this blog post, i will be able to allow you to skills to read content of images with Google Visio

Read More
How to get the last insert ID in Codeigniter, How to get the last insert ID in PHP

How to Enable seo url in opencart ?

Enable SEO URLs in the OpenCart administrator  Sign in to your OpenCart administrator boa

Read More
How to get the last insert ID in Codeigniter, How to get the last insert ID in PHP

How to Optimize Your Product Pages for SEO

Product pages are important for an eCommerce website. If you are planning to develop an eCommerce we

Read More