Tatnall has asked for the wisdom of the Perl Monks concerning the following question:
And then the execute and close subs. Sample of the CSV file, note, I artificially seperate each of these lines so the could be seen better:#!/usr/bin/perl print "Content-type: text/html\n\n"; use warnings; use CGI::Carp qw(fatalsToBrowser); use strict; use CGI; use Data::Dumper; #------------------------- declare -------------------------- my ($sth, $stmt); my $query = new CGI; my $file = $query->param('file'); my $table= $query->param('table'); #------------------------- connect -------------------------- my $databasename = "go_perl"; my $username = "uname"; my $password = "pword"; use DBI qw(:sql_types); my $dbh = DBI->connect("DBI:mysql:".$databasename, $username, $pas +sword, { RaiseError => 1},) or die "Connect failed: $DBI::errstr\n"; #--------------------- open .db file and insert $stmt =qq/LOAD DATA LOCAL INFILE "..\/file.csv" INTO TABLE table_name FIELDS TERMINATED BY "," OPTIONALLY ENCLOSED BY """" LINES TERMINATED BY "\r" IGNORE 1 LINES /; execute_it($dbh,$stmt); close_db($dbh, $sth); exit();
1,"01",0,"0000","00","0000000","Name Christine L","0000","Full","10",3 +5000,"10","100","0150","3","17","047","Teacher" 2,"01",0,"0000","00","0000000","Name Suzanne H","0000","Full","75",400 +70,"12","100","0070","3","25","047","Admin" 3,"01",0,"0000","00","0000000","Name Lorraine","0000","Full","09",4498 +0,"10","100","0200","4","17","093","Teacher" 4,"01",0,"0000","00","0000000","Name Laurie","0000","Full","75",45760, +"12","100","0090","5","17","047","Admin"
|
|---|