Zend Framework:如何检索最后插入的行的 id? [英] Zend Framework: How to retrieve the id of the last inserted row?

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

问题描述

我正在使用以下代码在我的数据库中插入一个新行:

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

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

如何获取我刚刚创建的这一行的行 ID?

How can I get the row id of the this row that I just created?

推荐答案

你试过了吗?这也很好用.

Did you try this ? This also works fine.

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

这篇关于Zend Framework:如何检索最后插入的行的 id?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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