Problem Solved...
Hello all,
I'm having trouble getting a CSV file to correctly import into MySQL using the following code. The first line gets put in and then stops completely. I've included some of the CSV file. Any help would be greatly appreciated. This is my first message on Perl Monks!
Here is the code I'm using:
#!/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();
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:
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"
"Recognizing who we aren't is only the first step toward knowing who we are." - Os Guinness