Here's some code that we use all day long to allow clients to refresh a database themself. Note: we have strong code ahead of this that validates the MIME type and file extension of their upload, and then code that checks the number of columns and names in the CSV file to match the DB table.
my $dbh = $self->dbconnect(server =>'master', db => 'admin'); my $stmt = qq~TRUNCATE TABLE $table~; #dump the old $dbh->do($stmt); $stmt = qq~LOAD DATA LOCAL INFILE ? INTO TABLE $table FIELDS TERMINATED BY "," LINES TERMINATED BY "\r\n" IGNORE 1 LINES~; my @bind = ("$path/$new_file_to_upload"); $dbh->do($stmt, undef, @bind); unlink "$path/$new_file_to_upload";
Watch the FIELDS/LINES TERMINATED BY... stuff.
Good luck!
In reply to Re: trying to execute "LOAD DATA INFILE" using DBI::Mysql
by bradcathey
in thread trying to execute "LOAD DATA INFILE" using DBI::Mysql
by jjohhn
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |