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

后端 未结 4 552
醉酒成梦
醉酒成梦 2021-01-17 13:06

I\'m inserting a new row into my database with this code:

$data = array(
    \'key\' => \'value\'
);
$this->getDbTable()->insert($data);
         


        
4条回答
  •  感动是毒
    2021-01-17 13:51

    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.

提交回复
热议问题