带有postgres的Zend DB与nextval()的问题

时间:2012-09-24 22:50:17

标签: php zend-framework postgresql zend-db nextval

好的,这是一个2部分问题,第一个主要问题是nextval()位。我有一个表,其中一列是自动递增列。作为postgres和Zend DB的新手,我遇到了麻烦。将新行插入表格。

这是我到目前为止(在CLI中这是有效的)。但不是在Zend DB的东西..

class Comments extends Zend_Db_Table_Abstract
{

    protected $_name = 'comments';

    public function setComment($comment_id = null, $id = null, $comment = null)
    {
        if(($comment_id == null)||(empty($comment_id))||(trim($comment_id) == '')){return false;}
        if(($id == null)||(empty($id))||(trim($id) == '')){return false;}
        if(($comment == null)||(empty($comment))||(trim($comment) == '')){return false;}

        echo 'check one';

        $db = Zend_Db_Table::getDefaultAdapter();
        if($comment_id == "none")
        {
            $created = time()*1000;
            $data = array(
                        "comment_id" => 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
                    );
            $table->insert($data);
            return true;
        }

    }
}

我得到的错误是:

  

致命错误:调用未定义的函数nextval()    /home/src/branches/portal/application/model/Comments.php 的   在线 45

所以不确定如何调整。我更熟悉mySQL,我可以放下NULL并自动递增。总而言之,最重要的问题是nextval,Zend DB在框架中有什么可以解决这个问题吗?

下一部分,因为这是一个两部分问题。使用$table->insert($data);会自动使用$_name变量吗?我通读了关于这个主题的Zend文档,但是目前我对如何在插入的情况下定义正确的表格感到困惑。

1 个答案:

答案 0 :(得分:2)

使用此:

"comment_id" => new Zend_Db_Expr("nextval('comments_comment_id_seq')"),