加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

zend-framework – ZF:参数号无效:没有绑定参数错误

发布时间:2020-12-13 18:02:40 所属栏目:PHP教程 来源:网络整理
导读:我创建了一个函数来获取像这样的表中的最后一个字段的值 private function _getLastPosition ($menuId) { $select = $this - getDbTable() - select(); $select - where("menu_id = ?",$menuId) - order('position DESC'); $row = $this - getDbTable() - fe
我创建了一个函数来获取像这样的表中的最后一个字段的值
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;
    }
}

当我跑的时候,我明白了

Message: SQLSTATE[HY093]: Invalid parameter number: no parameters were bound

请帮我解决这个问题

它通常意味着$menuId为空/ NULL.确保$menuId变量具有正确的值,然后在$select中使用它:

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

if(empty($menuId))
   return 0;

如果没有提供$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;
    }
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读