0

Just working through some legacy code updating to PDO, I keep getting an error with the following code:

$p = $productsperpage*($currentpage-1);
$productsperpage = 1;

$stmt = $db->prepare("SELECT * FROM `products` LIMIT :start,:results");
$stmt->bindParam(':start', $p, PDO::PARAM_INT);
$stmt->bindParam(':results', $productperpage, PDO::PARAM_INT);
$stmt->execute();

The problem seems to be with the limit using bound parameters, please can anyone help with getting this working?

The error :

Warning: PDOStatement::execute(): SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''1'' at line 2 in /test/category.php on line 163

Thanks

Masivuye Cokile
  • 4,754
  • 3
  • 19
  • 34
james q
  • 31
  • 2
  • 1
    what error you getting? – Masivuye Cokile Dec 15 '17 at 10:34
  • Warning: PDOStatement::execute(): SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''1'' at line 2 in /test/category.php on line 163 – james q Dec 15 '17 at 10:38
  • Hi, sorry forgot to mention I had tried casting to int but I get the following error when I do: Fatal error: Uncaught Error: Cannot pass parameter 2 by reference in /Applications/AMPPS/www/shellstore/category.php:163 Stack trace: #0 {main} thrown in /test/category.php on line 163 – james q Dec 15 '17 at 10:42
  • replace :start,:results with static values and check once... – K.B Dec 15 '17 at 10:49

0 Answers0