Tuesday, April 5, 2011

Codeigniter's insert_id()

I thought the insert_id() in codeigniter will insert an empty row and return the id. But I am wrong.

You should call insert() first and then call insert_id() to retrieved the id of newly inserted row.

like this:


$this->db->insert('table_name', $data);
$db_id = $this->db->insert_id();