This question already has an answer here:
SELECT id, content, date
FROM comment
WHERE post = ?
ORDER BY date DESC
LIMIT ?, ?
With PDO (I'm using MAMP 2.0.5 that has Apache 2.2.21, PHP up to 5.3.6, and MySQL 5.5.9) prepared statement this doesn't work, if I change the query with
LIMIT 0, 10
it works.
I see in the bugs of MySQL that this was a bug in previous version but I can't understand if this is still to be fixed.
If this is still a problem, there is a way to select a range of rows in another way?
code:
$comments = $db->prepare($query);
/* where $db is the PDO object */
$comments->execute(array($post, $min, $max));
will solve this problem.
Here's the problem:
The manual page for PDOStatement::execute() says (emphasis mine):
Thus your parameters are getting inserted as strings, so the final SQL code looks like this:
This is a particular case where MySQL will not cast to number but trigger a parse error:
What docs have to say:
Your choices include:
Bind parameters one by one so you can set a type:
Do not pass those values as parameters:
Disable emulated prepares (the MySQL driver has a bug/feature that will make it quote numeric arguments):