call any one tell me how to store text file information into mysql database
for example text file is:
StudentId |
Name |
Dept |
address |
city |
1 |
Chellappa |
CSE |
22 xx-colony 2nd street |
coimbatore |
2 |
Vijay |
IT |
23 yy colony |
coimbatore |
In this file (22 xx-colony 2nd street) and (23 yy colony) is address to store in database address column
This is my code
use DBI;
use strict;
my $driver = "mysql";
my $database = "TESTDB";
my $dsn = "DBI:$driver:database=$database";
my $userid = "root";
my $password = "1234";
my $dbh = DBI->connect($dsn, $userid, $password ) or die $DBI::errstr;
my $query = 'INSERT INTO student (StudentId,Name,Dept,address,city) VA
+LUES (?,?,?,?,?)';
my $sth = $dbh->prepare($query) or die "Prepare failed: " . $dbh->errs
+tr();
open my $fh, "<", "text.txt" or die $!;
<$fh>; #skip header
while (<$fh>)
{
chomp;
my @vals = split;
$sth->execute(@vals);
}
close $fh;
anyone can tell me the answer