ZF2如何获取最后的插入ID值? [英] ZF2 How to get last insert id value?

查看:76
本文介绍了ZF2如何获取最后的插入ID值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我坚持使用Zend Framework 2获取最后一个插入ID,我放弃了...

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

有尝试过的组合:

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

值正在插入到表中,但是每行(第一行除外,其int为 1)都返回空值。请不要告诉我,这么大的框架无法获得最后的插入ID值!?

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!?

推荐答案

此处我使用的是

$data = array()// Your data to be saved;
$this->tableGateway->insert($data);
$id = $this->tableGateway->lastInsertValue;

这篇关于ZF2如何获取最后的插入ID值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆