How to get last insert id in PHP Codeigniter?

How to get last insert id in PHP Codeigniter?

In this PHP Codeigniter Tutorial, I will let you know how to get 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 second table to create relation between both tables.

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

In Codeigniter, You can use insert_id() function to get latest auto incremented column value from the MySQL table.

insert_id() is function of "db" library. There are numbers of query helper method in Codeigniter.

Example :
function saveUserInfo(){
   $input = ['name'=>'Ajay Gupta', 'email'=>'ajay.agrahari09@gmail.com'];
   $this->db->insert('users', $input);
   $insertId = $this->db->insert_id();
   return  $insertId;
}

Phone: (+91) 8800417876
Noida, 201301
sakarya escort akyazı escort arifiye escort erenler escort eve gelen escort ferizli escort geyve escort hendek escort otele gelen escort sapanca escort söğütlü escort taraklı escort
sakarya escort sakarya escort sakarya escort sakarya escort sakarya escort sakarya escort sakarya escort serdivan escort sapanca escort karasu escort hendek escort ankara escort
sakarya escort kızlar sakarya escort kaliteli sakarya escort vip sakarya escort elit sakarya escort bayan sakarya escort adresleri.