PHP - Using PDO with IN clause array

前端 未结 8 1677
失恋的感觉
失恋的感觉 2020-11-21 06:03

I\'m using PDO to execute a statement with an IN clause that uses an array for its values:

$in_array = array(1, 2, 3);
$in_values = implode(\',\'         


        
8条回答
  •  迷失自我
    2020-11-21 07:05

    As I understand it it is because PDO will treat the $in_values contents as a single item and will quite it accordingly. PDO will see 1,2,3 as a single string so the query will look something like

    SELECT * FROM table WHERE my_value IN ("1,2,3")

    You may think that changing the implode to have quotes and commas will fix it, but it will not. PDO will see the quotes and change how it quotes the string.

    As to why your query matches the first value, I have no explanation.

提交回复
热议问题