Ananth Duari Ananth Duari - 1 year ago 176
MySQL Question

$this->db->insert_id() not working in mysql codeigniter

I am just trying to get the latest auto generated key from the mysql table from codeiginitor. But it is not working some how. I have tried this code


as well as


I am getting the following error

Severity: Notice

Message: Undefined property: CI_DB_mysql_driver::$insert_id

is the insert_id function not supported for mysql? How can we make it work?

Answer Source

This is the code I tried to insert the data and get the insert id,

$this->db->insert('table_name',$data); $id = $this->db->mysql_insert_id();

It is not working for me. I have used DB Driver as "mysql". Then I have installed "mysqli" and changed the DB driver name in database.php like,
$db['default']['dbdriver'] = 'mysqli';
Now it is working fine for me.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download