I have played with many permutations trying to get rid of the error, and finally turned on MySQL logging.
I my PHP I am getting this error:
Error selecting photographs: 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 ‘‘4’’ at line 1
The message is correct. The statement being executed by MySQL, according to the log, is:
SELECT * FROM photographs LIMIT ‘4’
The quotes around the 4 is the syntax error.
Now, in PHP, I am processing a POST with a function and the simplest code to replicate the error is:
function updatephotos($dbh, $x) {
$number = $x['number'] ;
$sql = 'SELECT * FROM photographs LIMIT :number';
$stmt = $dbh->prepare($sql);
try {
$stmt->bindParam( ':number', $number, PDO::PARAM_INT );
$stmt->execute();
} catch (PDOException $e) {
return 'Error selecting photographs: ' . $e->getMessage();
}
return "test worked" ;
}
$dbh is the handle to the DB created in the caller
$x is $_POST
If I echo $number I get: 4. No quotes.
I have tried using bindValue instead of bindParam.
I have tried not using PDO::PARAM_INT, and also using PDO::PARAM_STR
No matter what I do I ‘4’, instead of 4
I have a LAMP box. Ubuntu 11.04
Latest version of Apache, PHP and MySQL
Any and all help appreciated!