smith smith - 10 months ago 90
Perl Question

perl DBI and placeholders

I have this query

select * from table where ID in (1,2,3,5...)


How is it possible to build this query with the DBI using placeholders ?

for example :

my @list = (1, 2, 3, 4, 5);
my $sql = "select * from table where ID in (?)";

$sth->prepare($sql);
$sth->execute();


What argument should I send to execute? Is it a list or a string separated by
,
or something else?

Answer Source

This should build your query dynamically according to the number of items in your array

my @list =(1,2,3,4,5);
my $sql ="select * from table where ID in (@{[join',', ('?') x @list]})";
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download