簡體   English   中英

Zend框架:lastInsertId返回0

[英]Zend Framework: lastInsertId is returning 0

我目前正在從一本名為《 Appress Pro Zend Framework Techniques,建立一個完整的CMS項目》的書中學習Zend Framework,但是我陷入了提交錯誤后要重定向該頁面以confirm操作的問題,但是這種重定向取決於根據模型拋出的結果,將錯誤保存到數據庫。

這是模型錯誤的代碼

public function createBug($name, $email, $date, $url, $description, $priority, $status) {
    // create a new rows in the bugs table
    $row = $this->createRow();

    // set the row data
    $row->author = $name;
    $row->email = $email;
    $dateObject = new Zend_Date($date);
    $row->date = $dateObject -> get(Zend_Date::TIMESTAMP);
    $row->url = $url;
    $row->description = $description;
    $row->priority = $priority;
    $row->status = $status;

    //Save the new row
    $row->save();

    // now fetch the id of the row you just created and return it
    $id = $this->_db->lastInsertId();
    return $id;
}

記錄保存在數據庫中,但是$ id始終返回0,這導致重定向被轉義。

嘗試將$id設置$id $row->id lastInsertId() $row->id而不是lastInsertId()

大多數ORM都遵循這些原則。

 $id = $row->id;

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM