in reply to Re: Understanding placeholders
in thread Understanding placeholders
That's the first bit - use join and check the return values.foreach my $record (@filedata) { my @fields = split /,/, $record; my $placeholders = join ',', (('?') x @fields); my $sql = <<"END_SQL"; INSERT INTO $table VALUES ($placeholders) END_SQL my $sth = $dbh->prepare_cached($sql) || die "Could not prepare '$sql'\n"; $sth->execute(@fields) || die "Could not execute '$sql'\n"; $sth->finish; }
However, $record should be an arrayref, not a string. Which would mean that the split disappears. But, that's further back up the chain.
------
We are the carpenters and bricklayers of the Information Age.
Don't go borrowing trouble. For programmers, this means Worry only about what you need to implement.
Please remember that I'm crufty and crochety. All opinions are purely mine and all code is untested, unless otherwise specified.
|
|---|