how i can get the inserted id when I insert a record in this way using cakephp $this->query (" insert into [tablename] ([colname]) values([colvalue]);
A:
Assuming you are using MySQL you could perform the following query after you did the insert:
$array_with_id = $this->query('select last_insert_id() as id;');
But as mentioned by kouak, the usual way to insert data is to use the save() method. If you use this method, the id of the inserted record will then be automatically available in the $id property of the respective model.
dhofstet
2009-11-05 15:38:31
A:
If you use the the save() method you can get the id like so:
$this->Model->save($data);
$id = $this->Model->id;
Shard
2009-11-06 03:32:39
A:
Cake's model class has a function that gets the last inserted id:
$this->Model->getLastInsertID()
line 2584 in {project-folder}/cake/libs/model/model.php
centr0
2009-11-12 23:47:32