我一直在抓我的头在此代码为几个小时.... 没有道理给我,为什么它不工作使用bindParam与PDO
$isCorrect =($question->correct_answer == $body->answer) ? 1:0;
// the values are all there.......
// echo $body->question . "\n"; //335
// echo $body->user . "\n"; //51324123
// echo $question->day . "\n"; //0
// echo $isCorrect . "\n"; //0
//but still the below part fails.
$db = getConnection();
$sql = "INSERT INTO `answers` (`id`, `question_id`, `user`, `day`, `is_correct`) VALUES (NULL, ':question', ':user', ':day', :is_correct)";
$stmt = $db->prepare($sql);
$stmt->bindParam(":question_id", $body->question);
$stmt->bindParam(":user", $body->user);
$stmt->bindParam(":day", $question->day, PDO::PARAM_INT);
$stmt->bindParam(":is_correct", $isCorrect, PDO::PARAM_INT);
$stmt->execute();
给出了这样的错误:
SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens
我在计算4个标记...我错过了什么?显然我做错了什么。
有参数无效的数字,因为你把你的命名参数在单引号,这是不是这样做的方式。命名参数':question'不能放在单引号中,比'?' –