in reply to DBI and variable numbers of bind parameters
(I'm using perl 5.8.6 on freebsd, with mysql 4.0.21)my $in = "a,b"; my $sth = $dbh->prepare("SELECT foo FROM bar WHERE baz IN (?)"); $sth->execute( $in ); # fetch returns no results -- it would work if $in were just "a" my @in = qw/a b/; $sth = $dbh->prepare("SELECT foo FROM bar WHERE baz in (?,?)"); $sth->execute( @in ); # fetch returns expected results for "a" and "b"
Given that circumstance, I would definitely use the join( ',', map {'?'} @ins approach for putting together the text for the sql select statement (like davidrw showed in his reply).
|
|---|