in reply to Retrieving multiple records from database
Use the "IN" operator instead of "OR". Here's my favorite idiom (using placeholders):
my @ids_to_match = ( ... ); my $query = "SELECT somedata from table WHERE id IN (" . join(",", map {"?"} @ids_to_match ) .")"; my $sth = $dbh->prepare($query); $sth->execute(@ids_to_match);
Alternatively:
my $query = "SELECT somedata from table WHERE id IN (" . join(",", map { $dbh->quote($_) } @ids_to_match ) .")"; my $sth = $dbh->prepare($query); $sth->execute();
See DBI Recipes for more idioms.
_ _ _ _ (_|| | |(_|>< _|
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Retrieving multiple records from database
by mpeppler (Vicar) on Oct 17, 2004 at 15:58 UTC | |
Re^2: Retrieving multiple records from database
by bradcathey (Prior) on Oct 16, 2004 at 18:44 UTC | |
by jZed (Prior) on Oct 16, 2004 at 19:07 UTC | |
by davido (Cardinal) on Oct 17, 2004 at 06:38 UTC | |
by bradcathey (Prior) on Oct 17, 2004 at 11:52 UTC | |
by davido (Cardinal) on Oct 17, 2004 at 15:41 UTC |
In Section
Seekers of Perl Wisdom