0

So I'm currently new to PDO and its syntax. Can somebody help me with correctly doing the following SQL query in PDO:

SELECT * FROM Menu WHERE ID IN ([Array of IDs])

I currently have the following but I suspect it's wrong:

public function basket($ids) {
    require dirname(__FILE__) .  '/../../dbconnect.php';
    $sql = "SELECT * FROM `Menu` WHERE `ID` IN (:ids)";
    $stmt = $pdo->prepare($sql);
    $stmt->bindValue(':ids',$ids);
    $stmt->execute();
    $result = $stmt->fetchAll();
    echo json_encode($result);
}

Is my line with the SQL query correct ? I seem to be getting no results returned and no errors in my log files.

JamMan9
  • 706
  • 2
  • 9
  • 22
  • https://stackoverflow.com/questions/7044144/binding-parameters-for-where-in-clause-with-pdo – keja Feb 22 '18 at 08:50
  • You need to bind each value individually. – jeroen Feb 22 '18 at 08:50
  • As pure PDO doesn't seem to provide a good solution, you might as well consider using DBAL, which mostly follows PDO's API, but also adds some useful features http://docs.doctrine-project.org/projects/doctrine-dbal/en/latest/reference/data-retrieval-and-manipulation.html#list-of-parameters-conversion – Dienow Feb 22 '18 at 08:56

0 Answers0