(Caveat: this answer was written before the mysql tag was removed, I don't know if addslashes works for sqlite3.)
In PHP, $ list is given as an array of values โโfor the IN list:
$list = array(1, 2, 'abcd', 'double quote: "', "apostrophe: don't"); $ins = implode(', ', array_map( function($a) { return "'" . addslashes($a) . "'"; }, $list)); echo $sql = "... IN ($ins) ...";;
gives
... IN ('1', '2', 'abcd', 'double quote: \"', 'apostrophe: don\'t') ...
(Yes, this can be done using the usual for loop without using array_map and the "anonymous function".)
Do not worry; quotes around numbers ( '123' ) are OK for numeric columns.
Rick james
source share