获得以下错误:变量数量与预准备语句中的参数数量不匹配

时间:2015-04-23 14:12:30

标签: php mysql pdo

我收到此错误: 变量数量与预准备语句中的参数数量不匹配 我想我已经正确地写了声明,参数的数量也是一样的。请纠正我。

function Hello($questionId){
    global $mysqli,$db_table_prefix;
    $stmt = $mysqli->prepare("
        SELECT 
        id,
        answerby ,
        answer,
        questionId
        FROM ".$db_table_prefix."answers 
        WHERE `questionid` = 1
        ");
    $stmt->bind_param("s",$questionId);
    $stmt->execute();
    $stmt->bind_result($id, $answerby, $answer,$questionId);
    while ($stmt->fetch()){
        $row = array('id' => $id, 'answerby' => $answerby, 'answer' => $answer, 'questionId' => $questionId);
    }
    $stmt->close();
    return $row;

}

1 个答案:

答案 0 :(得分:0)

我编辑了代码,以便它可以工作。

函数Hello($ questionId){

    global $mysqli,$db_table_prefix;

    $stmt = $mysqli->prepare("
        SELECT 
        id,
        answerby ,
        answer,
        questionId
        FROM ".$db_table_prefix."answers 
        WHERE `questionid` = ?
        ");

    $stmt->bind_param("i",$questionId);
    $stmt->execute();

    $stmt->bind_result($id, $answerby, $answer,$questionId);

    while ($stmt->fetch()){

        $row = array('id' => $id, 'answerby' => $answerby, 'answer' => $answer, 'questionId' => $questionId);

    }

    $stmt->close();
    return $row;

}