How to get last inserted id from the mysql table in codeigniter
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 last inserted id from the table in CodeIgniter. Generally, the insert_id() CodeIgniter function returns the last inserting id from 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'];
$insertId = $this->db->insert_id();