Zend 数据库插入行的最后一个 ID.(使用 postgres) [英] Zend Database Last ID of inserted row. (Using postgres)
问题描述
好的,得到这个查询(工作正常,插入一个全部...)
Ok, got this query (works fine, inserts an all...)
$db = Zend_Db_Table::getDefaultAdapter();
$data = array(
"comment_id" => new Zend_Db_Expr("nextval('comments_comment_id_seq')"),
"comment" => $comment,
"comment_level" => 1,
"is_active" => true,
"status" => 0,
"id" => $id,
"user_id" => $_SESSION['role']['user_id'],
"ts_create" => $created,
"ts_mod" => $created
);
$db->insert($this->_name, $data);
$newID = $db->lastInsertId();
我什至尝试过
$newID = $db->insert($this->_name, $data);
而且我无法获取 ID 的值.它不是 mysql(i),所以我认为那是我的第一个问题,因为 postgres 似乎至少没有我习惯使用它的方式.所以我希望这里有人可以帮助我.无论如何要在新插入的项目上获取comment_id"列ID?因为现在我尝试了 lastInsertID,但我得到的结果都是 false 或 1,无论哪种情况都是错误的.
And I can't get the ID's value. Its not mysql(i) so I think thats my first issue, as postgres doesn't appear to have an autoincriment in the way I am used to working with it atleast. So I am hoping someone here can help me out. Anyway to get the "comment_id" columns id, on a new inserted item? Cause right now I try lastInsertID and all I get is false or 1 which in either case is wrong.
推荐答案
GordonM 为我指明了一个特定的 Zend 文档方向,通读该文档,我能够找到我需要的内容.不幸的是,没有人提供实际答案.所以我将回答我自己的问题,对于那些在陷入与我刚才类似的位置时可能会偶然发现它的人.. 但我会为 GordonM 投赞成票,让我朝着正确的方向前进.谢谢戈登
Well GordonM pointed me in the direction of a specific document for zend, that reading through that, I was able to find what I needed. Unfortunately no one provided an actual answer. So I am going to answer my own question, for those who may stumble across it when they are stuck in a similar position as I just was.. But will give the up-vote to GordonM for getting me in the right direction. Thanks GordonM
变化:
$newID = $db->insert($this->_name, $data);
致:
$newID = $db->lastSequenceId('comments_comment_id_seq');
这篇关于Zend 数据库插入行的最后一个 ID.(使用 postgres)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!