sql pdo php where in variable
问题 I'd like to select some data from my database using variables. Here is a short version of my code: // $a is either null or something like [1, 2] if ($a) { $debug = implode(',', $a); } else { $debug = [0-9]; } $sql = "SELECT id FROM user WHERE id IN ($debug)" How can I achieve that I get only user 1 and 2 (= value in $a ) if $a is set and all user if $a is not set? 回答1: First : be aware when you directly inject string inside queries, because you can be target of a SQL Injection Second : change