$pageMin = (($page * 10)-10);
$reponse = $bdd->prepare('SELECT pseudo, message FROM minichat ORDER BY id DESC LIMIT ?, 10');
$reponse->execute(array($pageMin));
看起来占位符不适用于LIMIT ......
当我与pageMin连接时,它可以工作,例如:
$reponse = $bdd->query('SELECT pseudo, message FROM minichat ORDER BY id DESC LIMIT' . $pageMin . ', 10');
甚至
$reponse = $bdd->prepare('SELECT pseudo, message FROM minichat ORDER BY id DESC LIMIT' . $pageMin . ', 10');
$reponse->execute(array());
使用占位符,它不会返回任何结果,为什么?
感谢您的帮助。
答案 0 :(得分:3)
当你将一个参数数组传递给execute
时,它们被视为字符串,而limit是一个int。只需使用类型为int的bindValue。
$reponse->bindValue(1, $pageMin, PDO::PARAM_INT);