Working With the LIMIT Operator in PDO in PHP
When working with the
LIMIT operator in a prepared query,
a problem may arise - numbers
in the query are automatically converted
into strings, which in turn will cause
an SQL syntax error.
The problem with incorrect
interpretation of numbers in the query can be solved
by binding variable values
using the bindValue method
and setting a numeric mode for them
using PARAM_INT:
<?php
$start = 2;
$count = 5;
$res = $pdo->prepare('SELECT * FROM users LIMIT ?, ?');
$res->bindValue(1, $start, PDO::PARAM_INT);
$res->bindValue(2, $count, PDO::PARAM_INT);
$res->execute();
$row = $res->fetchAll();
var_dump($row);
?>
Compose a IN query that
will output two users,
starting from the third.