How to get last inserted id from the mysql table in codeigniter – onlinecode

How to get last inserted id from the mysql table in codeigniter – onlinecode

In this post we will give you information about How to get last inserted id from the mysql table in codeigniter – onlinecode. Hear we will give you detail about How to get last inserted id from the mysql table in codeigniter – onlinecodeAnd how to use it also give you demo for it if it is necessary.

When we had fetched the last inserted ID into PHP, we were used to last auto-increment id. but CodeIgniter has provided an insert query (active record style) used to get last insert id.

In this Tutorial, I will inform you how to get the last inserted id from the table in CodeIgniter. Generally, the insert_id() CodeIgniter function returns the last inserting id from the Mysql database. Sometimes, when you need to insert a record of one table to another table at that time use insert_id function. We hope you can learn something from this post.

public function add()
{
	$arrData["first_name"] = $_POST['txtFirstName'];
	$arrData["last_name"] = $_POST['txtLastName'];
	$arrData["phone"] =  $_POST['txtPhone'];
	$this->db->insert('users', $arrData);
	
	$insertId = $this->db->insert_id();
}

Please follow and like us:

Hope this code and post will helped you for implement How to get last inserted id from the mysql table in 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

For More Info See :: laravel And github

Leave a Comment

Your email address will not be published. Required fields are marked *

  +  70  =  75

We're accepting well-written guest posts and this is a great opportunity to collaborate : Contact US