Hi I'm trying to select some random rows from table using MySQL PDO using PHP
$query = $conn->prepare("SELECT * FROM `products` WHERE `cat` = :cat ORDER BY RAND() LIMIT :limit_to");
$query->bindParam(':limit_to', $limit, PDO::PARAM_INT);
$query->bindParam(':cat', $cat, PDO::PARAM_INT);
$stmt = $query->execute();
However this throws a mysql syntax error like this,
"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 1"
What's causing this error and why? I don't see anything wrong in the
$limithave quotes? Seems like it does from the double single quotes around the2in the error message. Also not sure that the '2' from limit, is that the case?var_dump()of the variables?