Zend Framework: How to retrieve the id of the last inserted row? Zend Framework: How to retrieve the id of the last inserted row? php php

Zend Framework: How to retrieve the id of the last inserted row?


Did you try this ? This also works fine.

//just after you call your insert($data) function .. use this$lastInsertId = $this->getAdapter()->lastInsertId();


One gotcha. When calling $this->getDbTable()->insert($data); you have to make sure $data include the "primary key" of your table. For example, id=null if it's auto-increment. Otherwise, insert() will not return the last inserted ID.


Try below code:

To insert data:

$this->tableGateway->insert($data);

Get Last Inserted value:

$this->tableGateway->lastInsertValue;