Em PDO hoje foi a primeira vez que tive que por uma variável no LIMIT, e estou recebendo esse erro:
Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens' in nome-doarquivo.php:85 Stack trace: #0 nome-doarquivo.php(85): PDOStatement->execute(Array) #1 {main} thrown in nome-doarquivo.php on line 85
A linha 85 é essa:
$sql2->execute(array(":idQuiz" => $idQuiz));
Meu código:
$perguntaQuiz = 2;
$sql2 = $pdo->prepare('SELECT * FROM quiz_pergunta WHERE idquiz = :idQuiz ORDER BY id ASC LIMIT 0, :perguntaQuiz');
$sql2->bindParam(':perguntaQuiz', $perguntaQuiz, PDO::PARAM_INT);
$sql2->execute(array(":idQuiz" => $idQuiz));
O que estou errando?
(int)
não é necessário.cast
. Caso realmente precise dele, que no caso não parece ser necessário, faça-o anteriormente fora dobindParam
.