I'm used to doing something like the following for my queries:
$array = array(123,456,10,57,1024,768); //random data
$sql = "select * from table where field in(".implode(',',$array).")";
mysql_query($sql);
This works just fine, and is fast even when the array may have 1,000 or more items to search for(effectively a join against a nonexistent table). For me, this is quite useful because I am joining data from multiple sources together.
However, I know it is somewhat insecure -- SQL injection is possible if I don't escape my incoming data correctly.
I'd like to try to figure out a parametrized equivalent of this; some way to do that sort of "array IN" using more "hardened" code.
It may not be possible to do this directly, it may require a helper function that does the replacements. If so, I'm looking for a good one I can drop into my code, hopefully something that will allow me to just pass an array as a parameter.
While my example is for PHP, I also need to figure this out for Python, as I'm doing the same thing there.
I've read some similar questions here, but haven't seen any (good) answers.