I’m new to PDO and prepared statements. I recently tried to do something like this:
$pdo = $db->prepare('SELECT * FROM table LIMIT ?');
$pdo->execute(array(5));
This gives me an error saying there is a problem with my SQL syntax near the use of “5”. Can’t I use prepared statements with LIMIT? (The same problem occurs with ORDER BY)
I bow to logic_earths’ knowledge on this as I have never tried it, still, in the example you show us - I can’t see where you are binding the value in your prepare() statement?
Sure it can. Do it all the time. Whats probably happening is that LIMIT 5 is actually being generated as LIMIT ‘5’. Use bind parameter and specify a data type.