in reply to perl and mysql parse a text file
If your query requires one parameter, and you are passing an array, it's correct that only the first is inserted.
What you need is to prepare once aand execute many times.
my $sth = $dbh->prepare( "INSERT INTO data_profile (file) VALUES (?)") +; for (@array) { $sth->execute($_); }
Alternatively, you can create a multiple insert query.
# assume that @array contains qw(abc def ghi); my $query = 'INSERT INTO data_profile (file) VALUES '; $query .= join(',', map {'(?)'} @array); # now $query will be 'INSERT INTO data_profile (file) VALUES (?),(?),( +?)' $dbh->do($query, @array);
HTH
|
---|
Replies are listed 'Best First'. | |
---|---|
A reply falls below the community's threshold of quality. You may see it by logging in. |
In Section
Seekers of Perl Wisdom