Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

11
  • 37
    Thanks! But in PHP 5.3, the above code threw an error saying "Fatal error: Cannot pass parameter 2 by reference". It doesn't like casting an int there. Instead of (int) trim($_GET['skip']), try intval(trim($_GET['skip'])). Commented Apr 8, 2011 at 17:01
  • 6
    would be cool if someone provided the explanation why this is so...from a design/security (or other) standpoint. Commented Sep 25, 2012 at 0:23
  • 7
    This will only work if emulated prepared statements are enabled. It will fail if it is disabled (and it should be disabled!) Commented Nov 15, 2012 at 19:32
  • 4
    @Ross I cannot specifically answer this- but I can point out that LIMIT and OFFSET are features that were glued on AFTER all this PHP/MYSQL/PDO madness hit the dev circuit... In fact, I believe it was Lerdorf himself who oversaw LIMIT implementation a few years back. No, it doesn't answer the question, but it does indicate that it's an aftermarket add-on, and you know how well they can work out sometimes.... Commented Oct 13, 2013 at 0:55
  • 2
    @Ross PDO doesn't allow binding towards values - rather variables. If you try bindParam(':something', 2) you will have an error as PDO uses a pointer to the variable which a number can't have (if $i is 2 you can have a pointer towards $i but not towards the number 2). Commented Jun 20, 2014 at 8:34