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

In reply to Problem uploading 'large' CSV file using DBI by Tatnall

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.