0

I am trying to get this SQL to run, however when I use PDO it just displays nothing, I think its something to do with the ":offset" because if I remove that and type a number, it works fine. the offset variable is correct and functions as its supposed to

$newsQuery = $pdo->prepare("SELECT * FROM News ORDER BY News_ID DESC LIMIT 6 OFFSET :offset");
      echo $offset;
      $newsQuery->bindParam(":offset", $offset,PDO::PARAM_INT);
      $newsQuery->execute();
lmprowse
  • 113
  • 6

2 Answers2

2

Try this:

$newsQuery->bindParam(":offset", intval($offset), PDO::PARAM_INT);

For some reason, PDO::PARAM_INT is not enough. It is still passed as string. So, forcing an integer conversion bypasses this inconvenience.

Note: I've recently faced this myself.

Alex Tartan
  • 6,736
  • 10
  • 34
  • 45
-1

Just replace below line

$newsQuery->bindParam(":offset", $offset,PDO::PARAM_INT);

With

$newsQuery->bindParam("offset", $offset,PDO::PARAM_INT);

Where ever you have to bind :parameter do not use : sign while bind time.

Ahesanali Suthar
  • 341
  • 3
  • 23