Reputation: 155
I would like to insert a single row through perl dbi, but this row has A LOT of columns. My query would be smt like this :
$sth->prepare("insert into bigtable (col1, col2, ..., col25) values (?, ?, ..., ?)");
$sth->execute($val1, $val2, ..., $val25);
But I want it cleaner. If I have an array, @myArray, containing these 25 variables, is there a way to do smt like this :
$sth->prepare("insert into bigtable (col1, col2, ..., col25) values (?, ?, ..., ?)");
$sth->execute(@myArray);
?
Upvotes: 2
Views: 935
Reputation: 67900
You can do:
my $placeholders = join ", ", ("?") x @array;
$sth->prepare("insert into bigtable (col...) values ($placeholders)");
$sth->execute(@array);
Upvotes: 4