参数号无效:致命错误

时间:2016-10-21 15:39:26

标签: php

 /* News Feed Data */
     public function newsFeed()
     {
        $db = getDB();
        $stmt = $db->prepare("SELECT user.id as id, user.nome as nome, app.id as app_id, app.nome as app_nome, app.descricao as app_descricao, app.like_count as like_count FROM  user , app  WHERE user.id=app.user_id ORDER BY app.id DESC");  
        $stmt->execute();
        //$this->pdo->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING );
        $data = $stmt->fetchAll(PDO::FETCH_OBJ);
        $db = null;
        return $data;
     }

      /* User Reaction Check */
     public function reactionCheck($uid, $msg_id)
     {
        $db = getDB();
        $stmt = $db->prepare("SELECT app_like.id , reaction.name from app_like, reaction WHERE reaction.id=app_like.reaction_id AND app_like.user_id=:uid  AND app_like.app_id=:id");  
        /*$stmt->bindValue(':id', $uid, PDO::PARAM_INT);
        $stmt->bindValue(':app_id', $msg_id, PDO::PARAM_INT);*/
        $stmt->execute(array(':id' => $uid,
                  ':app_id' => $msg_id));
        /*$stmt->execute(array(':id'  => $uid, ':app_id'  => $msg_id));*/
        $this->pdo->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING );
        $data= $stmt->fetch(PDO::FETCH_OBJ);
        $db = null;
        return $data;
     }

我遇到致命错误问题:未捕获异常'PDOException',消息'SQLSTATE [HY093]:参数号无效:参数未定义'在C:\ xampps \ htdocs \ review \ feed.php:29 Stack trace:#0 C:\ xampps \ htdocs \ review \ feed.php(29):PDOStatement-> execute(Array)#1 C:\ xampps \ htdocs \ review \ indexa.php(36):feed->在第29行的C:\ xampps \ htdocs \ review \ feed.php中抛出的reactionCheck('4','4')#2 {main}

1 个答案:

答案 0 :(得分:0)

绑定中有错误。您在查询中有:uid但绑定中有:id。 这应该有效:

    $stmt = $db->prepare("SELECT app_like.id , reaction.name from app_like, reaction WHERE reaction.id=app_like.reaction_id AND app_like.user_id=:uid  AND app_like.app_id=:id");  

    $stmt->execute(array(':uid' => $uid,
              ':id' => $msg_id));