I'm trying to make a following query:
SELECT * FROM data WHERE ID IN ('$data')
While the $data is:
Array
(
    [0] => 2
    [1] => 4
)
But the output is: "Array to string conversion"
However if I do SELECT * FROM data WHERE ID IN (2, 4) everything works!
How do I change the array to this kind of string of numbers, please?


.. WHERE ID IN (?, ?)or as appropriate), then bind to each element of the array. Then the question is: "How can I turn an array of N elements into the string?, .., where ? is repeated N times?".. IIRC, some adapters already support array-binding to multiple expansion. This problem is not novel: expand searches to look for the end problem being solved.[2,4]into'2,4'. In which case the answer would beexplode(',',$data. But, this is unfortunately the wrong question, because that’s not the proper way to do this query. If using prepared statements in pdo, no conversion is needed:$stmt = $pdo->prepare(‘SELECT * FROM data WHERE ID IN(?,?); $stmt->execute ($data);$datais not user input in anyway, but values created via code (trusted), you can bypass the complexity of a prepared statement and useimplodethere. If you cannot trust the values in$data, see all above. You dont have to use a prepared statement for everything, needlessly.