-1

This is PHP / CodeIgniter / MySQL

The only way I can think of is to do the insert ($this->db->insert(...)), and then immediatly after, run another query to find the record again.

I'm hoping there is something (which seems a bit more efficient to me) that returns the primary key (or something) of the newly added record.

Maxcot
  • 1,513
  • 3
  • 23
  • 51

2 Answers2

2

For codeigniter

$this->db->insert_id()
Leetbulb
  • 416
  • 2
  • 6
0

Have a look at here http://ellislab.com/codeigniter/user_guide/database/helpers.html and the first function is $this->db->insert_id();

This also works with activerecord inserts.

or you can do

$last_insert_id = $this->db->call_function('insert_id');  
Kumar V
  • 8,810
  • 9
  • 39
  • 58
Suvash sarker
  • 3,140
  • 1
  • 18
  • 21