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

后端 未结 4 485
醉酒成梦
醉酒成梦 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:53

    There is also newId function, witch returns the next new ID, so you can use it to insert a new row.

    $id = $this->getDbTable->newId('table_name', 'id');
    
    $data = array(
        'id' => $id,
        'data' => $data
    );
    
    $this->getDbTable->insertRow('table_name', $data);
    

    Now you can do whatever you want with your $id.

提交回复
热议问题