1

The following statement written in php for a mysql database always brings me the error "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''10'' at line 1'".

('SELECT `creator`,`created`,`content` 
FROM mytable 
WHERE `groupid`=? 
ORDER BY `created` DESC 
LIMIT ?', $foo, 10)

When I replace the questionmark with a number, it works.

Where is my mistake?

3
  • 1
    Bind variables can't be applied to limits, in the same way you can't use bind variables for table names or column names, order direction, etc Commented Nov 8, 2014 at 14:47
  • But why? I mean - is there any reason behind this? Commented Nov 8, 2014 at 15:22
  • Why? Because of the way bind variables actually work, and what they actually do..... they're not simply a plug-and-play anywhere in a query, but are specific to dynamic arguments used in your WHERE clause Commented Nov 8, 2014 at 15:24

1 Answer 1

1

You can't bind number to the LIMIT .. just add it to the actual query:

('SELECT `creator`,`created`,`content` 
FROM mytable 
WHERE `groupid`=? 
ORDER BY `created` DESC 
LIMIT ' . 10, $foo)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.