Results 1 to 2 of 2
  1. #1
    Join Date
    Nov 2007
    Posts
    14

    Unanswered: PDO, Limit and BindParam

    ... Using MySQL 5 and PHP 5.2.3

    Code:
    $stmt = $dbh->prepare('SELECT advert_title,advert_body from Ads WHERE isFeatured=1 Limit 1,:offset');
    $stmt->bindValue(':offset',$_GET['offset'],PDO::PARAM_INT);
    For the life of me I can't get the above to work and after an hour i still have no clue why. That query works fine if i manually code the limit in, or if i place the ffset placeholder anywhere else...

    Error returned by $stmt->errorInfo(): 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 ''1'' at line 1

    ... I'm guessing thats because its trying to pass a string in when it probably shouldn't be.

    The purpose of the query is to return the nth advert in a list of featured ad's.

    Anyone have any ideas?

    Cheers.
    Last edited by Genx; 12-12-07 at 10:48.

  2. #2
    Join Date
    Nov 2007
    Posts
    14
    Well, nothing I tried works, so it seems that i'll just have to feed this particular variable directly into the sql statement using something like intval($_GET['foo']) given that it will always be an int anyway.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •