Here is my code:
$arr = [val1, val2, val3];
$str = join("','",$arr); //=> val1','val2','val3
$stm = $dbh->prepare("SELECT * FROM mytable WHERE mycol NOT IN ('$str')");
$stm->execute();
Code above works as well. Now I want to pass that variable to the query instead of using it into the query directly. Something like this:
$arr = [val1, val2, val3];
$str = join("','",$arr); //=> val1','val2','val3
$stm = $dbh->prepare("SELECT * FROM mytable WHERE mycol NOT IN (':str')");
$stm->execute(array('str' => $str));
But it doesn't work. There is syntax error (I'm pretty sure the problem is about quotes) ..!
Note: Sometimes $str
is empty.
Anyway, how can I handle quotes?