pdo prepare语句don';我不能极限工作


pdo prepare statement don't work with limit

我尝试了一些方法,但没有成功。这是我的请求:它使用数字而不是:limit,但当我尝试使用变量时,它不会。我将非常感谢你的帮助或一些线索,看看哪里。干杯K.

导致问题的线路:

$req = $bdd->prepare('SELECT * FROM Twit ORDER BY id DESC LIMIT 0, :limit');
$req->bindParam(':limit',$page,PDO::PARAM_INT);

整个代码以防万一:

    <?php
//echo $_COOKIE['pseudo'] ."<br>";
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
</head>
<body>
<form action="minichat_post.php" method="POST">
    <label for="pseudo">Pseudo</label>
    <input type="text" name="pseudo" value="<?php
    if (isset($_COOKIE['pseudo'])) {
        echo $_COOKIE['pseudo'];
        }else{echo "";};?>">
    <br /><br />
    <label for="msg">message</label>
    <input type="text" name="msg"><br /><br />
    <input type="submit" value="Envoyer">
</form>
<div class="container">
<?php
//connection
try
{
    $bdd = new PDO('mysql:host=localhost;dbname=minichat;charset=utf8', 'root', 'root');
}
catch (Exception $e)
{
        die('Erreur : ' . $e->getMessage());
}
//requête 
$req = $bdd->query('SELECT * FROM Twit ORDER BY id DESC LIMIT 0,10');
//récupération
while ($donnees = $req->fetch()){
    echo '<p><strong>' . htmlspecialchars($donnees['pseudo']) . '</strong> : ' . htmlspecialchars($donnees['msg']) . '</p>';
}
$req->closeCursor();
?>
<form action="" method="GET">
<label for="page">Combien de msg voulez vous voir</label>
<input type="text" name="page">
<input type="submit" value="voir"></input>
</form>
<?php
$page=htmlspecialchars($_GET['page']);
//connection
if (isset($page) && !empty($page)) {
    try
{
    $bdd = new PDO('mysql:host=localhost;dbname=minichat;charset=utf8', 'root', 'root');
}
catch (Exception $e)
{
        die('Erreur : ' . $e->getMessage());
}

//request WHERE MY PROBLEM IS
/*I've tried that - din't work neither
$req = $bdd->prepare('SELECT * FROM Twit ORDER BY id DESC LIMIT 0, ?');
$req->execute(array(htmlspecialchars($_GET['page'])));*/
$req = $bdd->prepare('SELECT * FROM Twit ORDER BY id DESC LIMIT 0, :limit');
$req->bindParam(':limit',$page,PDO::PARAM_INT);

print_r($req);
//fetchingdata
    while ($donnees = $req->fetch()){
        echo '<p><strong>' . htmlspecialchars($donnees['pseudo']) . '</strong> : ' . htmlspecialchars($donnees['msg']) . '</p>';
    }
}
$req->closeCursor();
?>
</div>
</body>
</html>

尝试将$page变量强制转换为(int)$page