Logo

Office Address

123/A, Miranda City Likaoli
Prikano, Dope

Phone Number

+0989 7876 9865 9

+(090) 8765 86543 85

Email Address

info@example.com

example.mail@hum.com

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

CodeIgniter upload multiple images using drag and drop using dropzone

CodeIgniter upload multiple images using drag and drop using dropzone

In this example we are going to explain how to upload mulitple images using dropzone library in Codeigniter. Simple drag and drop image on the webpage. dropzone jQuery plugin, you can easily upload im

Read More
Outsource WordPress Development

Outsource WordPress Development

Blazingcoders: Your Ideal WordPress Development Partner Our specialty at Blazingcoders is providing premium, tailored WordPress development services. Our team is capable of managing projects of any

Read More
Why Outsourcing Web Development is the Smartest Choice for Business Enhancement

Why Outsourcing Web Development is the Smartest Choice for Business Enhancement

The practice of assigning the creation of your website to an outside company or person with the specific training and experience required to create safe, secure, and functional solutions is known as o

Read More