php 最后插入 id 与 zend db 表摘要

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4842064/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 14:32:21  来源:igfitidea点击:

last insert id with zend db table abstract

phpzend-frameworkinsertzend-db

提问by Santosh Linkha

variable $tablemodelin an instance of a model which extends Zend_Db_Table_Abstract, if i do

$tablemodel扩展模型实例中的变量Zend_Db_Table_Abstract,如果我这样做

$tablemodel->insert($data)

to insert data. Is there any method or property to get last insert id?

插入数据。是否有任何方法或属性来获取最后一个插入 ID?

regards

问候

回答by Haim Evgi

try

尝试

$id = $tablemodel->insert($data);  
echo $id;

回答by Art3mk4

$last_id = $tablemodel->getAdapter()->lastInsertId();

回答by dckur

you can use lastInsertId Method

你可以使用 lastInsertId 方法

echo 'last inserted id: ' . $db->lastInsertId();

回答by RaviPatidar

use after insert query

插入查询后使用

$this->dbAdapter->getDriver()->getLastGeneratedValue();

回答by glitchyme

$insert_id = $this->db->getLastId()worked for me

$insert_id = $this->db->getLastId()为我工作