3
$pageMin = (($page * 10)-10);

$reponse = $bdd->prepare('SELECT pseudo, message FROM minichat ORDER BY id DESC LIMIT ?, 10');
$reponse->execute(array($pageMin));

It seems like the placeholders don't work for LIMIT...

When I concatenate with pageMin it works, ex:

$reponse = $bdd->query('SELECT pseudo, message FROM minichat ORDER BY id DESC LIMIT' . $pageMin . ', 10');

or even

$reponse = $bdd->prepare('SELECT pseudo, message FROM minichat ORDER BY id DESC LIMIT' . $pageMin . ', 10');
$reponse->execute(array());

Using the placeholder, it does not return me any results, why?

Thank you for helping.

  • I'm not sure about the real question, but wouldn't `LIMIT' . $pageMin . '`, if `$pageMin` was, say, '5', evaluate to `LIMIT5` (no space)? Try making it `LIMIT '.$pageMin.'` – Scott Jun 01 '13 at 01:12
  • It's just a typing error, it works when I concatenate, my problem is when I want to use placeholders ex: LIMITE ?, 10, then it does not work. –  Jun 01 '13 at 01:15
  • I don't get any error, but my results are not good (just no results) –  Jun 01 '13 at 01:15

1 Answers1

4

When you pass an array of params to execute they are treated as strings and limit is an int. Just use bindValue with type int.

$reponse->bindValue(1, $pageMin, PDO::PARAM_INT);
Musa
  • 96,336
  • 17
  • 118
  • 137