0

可能重复:
PHP PDO bindValue in LIMIT

    $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,它的工作原理。请赐教。谢谢。

4

1 回答 1

1
$topics=$dbh->prepare("...LIMIT :limit");
$topics->bindValue(':limit', intval($number), PDO::PARAM_INT);
$topics->execute();
于 2012-06-09T17:36:55.590 回答