PDO and LIMIT syntax
Posted: Thu Aug 27, 2015 9:02 am
I have the following code:
$amount is a value passed to the function and is an integer. An error occurs when I execute the query
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 ''2'' at line 2
If i try the code with a value not passed from the function, the query executes and the script does what it's supposed to. I also bound a parameter to see if that might work but I receive the same error. I'm using PHP Version 5.3.8 if that's of any help.
Thanks
Code: Select all
<?php
$result = false;
$statement = $this->_pdoObj->prepare("SELECT * FROM shop_stock LIMIT 0, ?");
//$statement->bindParam(':amount', $amount);
$statement->bindValue(1, $amount);
?>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 ''2'' at line 2
If i try the code with a value not passed from the function, the query executes and the script does what it's supposed to. I also bound a parameter to see if that might work but I receive the same error. I'm using PHP Version 5.3.8 if that's of any help.
Thanks