Zend framework ZF:无效的参数编号:未绑定任何参数错误

Zend framework ZF:无效的参数编号:未绑定任何参数错误,zend-framework,Zend Framework,我创建了一个函数来获取表中最后一个字段的a值,如下所示 private function _getLastPosition ($menuId) { $select = $this -> getDbTable() -> select(); $select -> where("menu_id = ?", $menuId) -> order('position DESC'); $row = $this -> getDbTab

我创建了一个函数来获取表中最后一个字段的a值,如下所示

private function _getLastPosition ($menuId) {
    $select = $this -> getDbTable() -> select();
    $select -> where("menu_id = ?", $menuId)
            -> order('position DESC');
    $row = $this -> getDbTable() -> fetchRow($select);
    if($row) {
        return $row -> position;
    } else {
        return 0;
    }
}
当我运行它时,我得到

消息:SQLSTATE[HY093]:参数编号无效:未绑定任何参数


请帮助我修复此问题,它通常意味着$menuId为空/NULL。在$select中使用$menuId变量之前,请确保该变量具有正确的值:

在$select->where()调用中使用$menuId之前,可以在函数开头添加以下行:

如果未提供$menuId,则返回0。如果要在这种情况下引发错误(异常),可以执行以下操作:

if(empty($menuId))
   throw new Exception("No Menu ID Provided"); 
您的完整功能如下所示:

private function _getLastPosition ($menuId) {
    if(empty($menuId))
       throw new Exception("No Menu ID Provided");
    $select = $this -> getDbTable() -> select();
    $select -> where("menu_id = ?", $menuId)
            -> order('position DESC');
    $row = $this -> getDbTable() -> fetchRow($select);
    if($row) {
        return $row -> position;
    } else {
        return 0;
    }
}

是的,它是空的。谢谢,我修好了。但其他错误也在不断出现:(。
private function _getLastPosition ($menuId) {
    if(empty($menuId))
       throw new Exception("No Menu ID Provided");
    $select = $this -> getDbTable() -> select();
    $select -> where("menu_id = ?", $menuId)
            -> order('position DESC');
    $row = $this -> getDbTable() -> fetchRow($select);
    if($row) {
        return $row -> position;
    } else {
        return 0;
    }
}