On Thu, 2002-05-16 at 16:55, Kevin O wrote:
> Hello all,
> 
> I need to insert a lot of data into a mysql table.  Know that I can do it 
> like this example:
> 
> 
> 
>  my $sth = $dbh->prepare(q{
>     INSERT INTO sales (product_code, qty, price) VALUES (?, ?, ?)
>   }) or die $dbh->errstr;
>   while (<>) {
>       chomp;
>       my ($product_code, $qty, $price) = split /,/;
>       $sth->execute($product_code, $qty, $price) or die $dbh->errstr;
>   }
>   $dbh->commit or die $dbh->errstr;
> 
> 
> My problem is, I have 500 fields.  I know I can start the Insert statement 
> like INSERT INTO mytable VALUES - cause I'm inserting a value for every 
> field in the database, but do I have to type a "?" for all 500 fields?  BTW, 
> I'm just feeding execute with an array of values, like above.
> 
> Any help is appreciated,
> Kevin

while (<>) {
        chomp;
        my $query  = "INSERT INTO sales(";
        $query    .= $dbh->quote($_) . ',' for split /,/;
        $query     =~ s/,$/)/;
        $dbh->do($query) or die $dbh->errstr;
}
$dbh->commit or die $dbh->errstr;
        


 
-- 
Today is Sweetmorn the 63rd day of Discord in the YOLD 3168
Fnord.

Missile Address: 33:48:3.521N  84:23:34.786W


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to