in reply to Understanding placeholders
instead of
foreach my $record (@filedata) { my $sql = "INSERT INTO $table VALUES ($record)"; my $rows = $dbh->do($sql); }
you could do something like:
foreach my $record (@filedata) { my @fields = split /,/, $record; my $placeholders = "?," x scalar (@fields); chop $placeholders; # remove the end ',' my $sql = "INSERT INTO $table VALUES ($placeholders)"; my $sth = $dbh->prepare($sql); my $rows = $sth->execute(@fields); $sth->finish(); }
and, of course, if all the lines of @filedata are for the same table, you could move some of that code outside the loop.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Understanding placeholders
by perlplexer (Hermit) on May 03, 2003 at 22:04 UTC | |
|
Re: Re: Understanding placeholders
by nedals (Deacon) on May 04, 2003 at 16:24 UTC | |
|
Re: Re: Understanding placeholders
by dragonchild (Archbishop) on May 06, 2003 at 13:58 UTC |