I'm learning the ropes with PDO.
Here is my sql (the number of parameters that can appear in the WHERE is variable).
SELECT
ID, title
FROM
table
WHERE
something = ?
ORDER BY
:sort :dir
LIMIT
:start, :results
Here is my code:
$query = $conn->prepare($sql);
if ($parameters) {
$i = 0;
foreach ($parameters AS $parameter) {
$i++;
$query->bindParam($i, $parameter);
}
}
$query->bindParam(':start', $pagination['start'], PDO::PARAM_INT);
$query->bindParam(':results', $pagination['results'], PDO::PARAM_INT);
$query->bindParam(':sort', $pagination['sort']);
$query->bindParam(':dir', $pagination['dir']);
$query->execute();
... and here is the exception that it generates:
Invalid parameter number: mixed named and positional parameters
Is it impossible to combine positional and named parameters in the same query? Or am I missing something?
Thanks!