$number=8;
try {
$topics=$dbh->prepare("SELECT * FROM topictable ORDER BY RAND() LIMIT ?");
$topics->execute(array($number));
$topicarray = $topics->fetch(PDO::FETCH_BOTH);
print_r($topicarray);
}
catch(PDOException $e) {
echo $e->getMessage();
}
以上是我的代码,我知道问题来自$topics=$dbh->prepare("SELECT * FROM topictable ORDER BY RAND() LIMIT ?")
,因为当我改变时?到8,它的工作原理。请赐教。感谢。
答案 0 :(得分:1)
$topics=$dbh->prepare("...LIMIT :limit");
$topics->bindValue(':limit', intval($number), PDO::PARAM_INT);
$topics->execute();