0

I have this piece of code which should retrieve 10 records at once from my database table:

$query = 'SELECT *
          FROM shares
          ORDER BY create_date DESC
          LIMIT :sharesPerPage OFFSET :lowerBound';
$this->prepare($query);
$this->bind(':sharesPerPage', $sharesPerPage);
$this->bind(':lowerBound', $lowerBound);
$this->execute();

For some reason a PDO Exception is being thrown with information that I have wrong syntax around '10' OFFSET '0', which corresponds to $sharesPerPage and $lowerBound respectively.

I have checked everything already, but the query still evaluates to an error. What is wrong with that code?

manjii
  • 149
  • 2
  • 12

1 Answers1

2

you have to cast your value into int. Otherwise it will converted as string

$this->bind(':sharesPerPage', (int)$sharesPerPage, PDO::PARAM_INT));
$this->bind(':lowerBound', (int)$lowerBound, PDO::PARAM_INT));
B. Desai
  • 16,414
  • 5
  • 26
  • 47