Hope this complete example using DBI will assist you. I think this is enough framework for you to extend it to your specific needs. This is one of many simple ways to use DBI.

To use this approach your webhost must have the DBI and DBD-MySQL Perl modules installed. You can write a test program to see if Perl can "find" these modules or call their customer service.
use strict; use DBI; print "$0\t\tStart: ",scalar localtime,"\n"; my $driver = "mysql"; my $database = "enter_dbname_here"; my $hostname = "enter_hostname_here"; my $user = "root"; my $password = ""; my $dsn = "DBI:$driver:$database:$hostname"; my $dbh = DBI->connect($dsn,$user,$password) or die "Error $DBI::errst +r connecting to $dsn\n"; $dbh->do('DELETE FROM YOURFILE'); open(FILEIN,'c:\input.txt') or die "Can't open FILEIN file: $!\n"; my $sql=q/INSERT INTO YOURFILE (YOURFIELD_1, YOURFIELD_2, YOURFIELD_3) values (?,?,?)/; my $sth=$dbh->prepare( $sql ) or die "Cannot prepare SQL: $DBI::errstr + \n"; my $line=<FILEIN>; # Ignore Header if you have one while ($line=<FILEIN>) { chomp($line); my ($f1,$f2,$f3) = (split /\t/, $line); $f1 =~ s/"//g; # Remove double quotes from input if needed $f1 =~ s/,//g; # Remove commas from input if needed # tr/// may work better for your situation? # etc ... # These match the values (?,?,?) in the INSERT above $sth->bind_param(1,$f1); $sth->bind_param(2,$f2); $sth->bind_param(3,$f3); # Write to mySQL database $sth->execute or die "Cannot execute SQL: $DBI::errstr \n"; } close(FILEIN); $dbh->disconnect; print "$0\t\t End: ",scalar localtime,"\n"; __END__

..:::::: aquacade ::::::..


In reply to Re: Perl and Mysql by aquacade
in thread Perl and Mysql by La12

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.