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 ::::::.. |