ZF2 How to get last insert id value?

2019-03-18 04:12发布

I am stuck with getting last insert id with Zend framework 2 and I gave up on this...

There are tried combinations:

var_dump($this->tableGateway->insert($insert));
var_dump($this->tableGateway->lastInsertValue);
var_dump($this->tableGateway->getLastInsertValue());
var_dump($this->tableGateway->getAdapter()->getDriver()->getConnection()->getLastGeneratedValue());

Value is inserting to table, but every line (except first, which gives int "1") returns null. Please don't tell me, that such a big framework does not give possibility to get last insert id value!?

7条回答
乱世女痞
2楼-- · 2019-03-18 04:39

Here is what I use:

$data = array()// Your data to be saved;
$this->tableGateway->insert($data);
$id = $this->tableGateway->lastInsertValue;
查看更多
登录 后发表回答