How to get last insert id in PHP Codeigniter – onlinecode
In this post we will give you information about How to get last insert id in PHP Codeigniter – onlinecode. Hear we will give you detail about How to get last insert id in PHP Codeigniter – onlinecodeAnd how to use it also give you demo for it if it is necessary.
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; }
Try this..
Hope this code and post will helped you for implement How to get last insert id in PHP Codeigniter – onlinecode. if you need any help or any feedback give it in comment section or you have good idea about this post you can give it comment section. Your comment will help us for help you more and improve us. we will give you this type of more interesting post in featured also so, For more interesting post and code Keep reading our blogs