2
<?php
    $current = 0;
    $results = 5;
    $statement = $db->prepare("SELECT title, id FROM mytable LIMIT ?, ?");
    $statement->execute(array($current, $results));
?>

var_dump($statement);
=> public 'queryString' => string 'SELECT title, id FROM mytable LIMIT ?, ?' (length=39)

Can anyone help me find why this isn't working?

Adonis K. Kakoulidis
  • 4,951
  • 6
  • 34
  • 43

2 Answers2

2

You need to bind those parameters as integers, and not as strings (default). Binding parameters as strings adds quotes around them automatically.

$statement->bindParam(":current", $current, PDO::PARAM_INT)

This example uses named placeholders. I recommend you used it regardless.

Madara's Ghost
  • 172,118
  • 50
  • 264
  • 308
1

letting you see a string with the placeholders replaced by the supplied values isn't a feature that pdo offers. It will however, properly execute the prepared statement with your values.

For pdos mysql driver, there's a peculiarity when binding values for part of the limit clause, if using execute() on an array of values. See How can I pass an array of PDO parameters yet still specify their types?

Community
  • 1
  • 1
goat
  • 31,486
  • 7
  • 73
  • 96