![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
| Hi, I am dropping this email because I have already tried all possible ways. Goal: Migrate Excel to Mysql using perl . Howto: I have save the xls file as CVS ( comma - separate ) format like: i.e: ELTID,Telecom ID,ELTID8,ELTID Greek ATX (Cook),682-60127,Greece-->Cook Island,GR,27-Apr-98 ++++++++++++++++++++++++++++++++++++++++++++++++++ +++++++++++ perl program: #Initialization of Libraries needed it. use DBI; use DBD::mysql; #Initialization of database my $table="dnis"; my $db="stats"; my $user="user"; my $pass=" password"; my $sth2; my $i=0; my $sqlrecords; my $export_sql; my $source="/home/canario/eltid.txt"; #$LOGFILE="ELTID.csv "; # Tell the script that we will use Mysql database my $drh=DBI->install_driver('mysql'); # Establish connectin with the database my $dbh=$drh->connect($db,$user,$pass); # A simple check to see if we connect6 if (!$dbh) { print "cannot connect: $DBI::errstr<br>"; die; } open(LOG,$source) or die("Could not open log file."); foreach $line (<LOG>){ #while (<LOG>) { my ($ipcode, $ip_name, $prod_id, $prod_name, $actual_num, $rate_desc, $country, $updated)=split(/,/,$line); print "column: $i\n"; print "ipcode:$ipcode\n"; print "ip_name:$ip_name\n"; print "prod_id:$prod_id\n"; print "prod_name:$prod_name\n"; print "actual_num:$actual_num\n"; print "rate_desc:$rate_desc\n"; print "country:$country\n"; print "updated:$updated\n"; $i++; #if ipcode is not null then -> Export the data to the Mysql database #if ($ipcode !="") { $sqlrecords = "insert into $table(ipcode,ip_name,prod_id,prod_name,actual_num ,rate_desc,country,updated) values ('$ipcode','$ip_name','$prod_id','$prod_name','$ac tual_num','$rate_desc','$country','$updated')"; print "$sqlrecords\n"; # } #$sth2=$dbh->prepare($sqlrecords); $sth2=$dbh->do($sqlrecords); #$export_sql=$sth2->execute(); } close(LOG); $sth2->finish; $dbh->disconnect; ++++++++++++++++++++++++++++++++++++++++++++++++++ +++++++++++++++++++++++++++++++ Description of program: It read from cvs file row by row and it goes insert the data read from file into mysql table. Just a simple loop with single query. I have checked the log file from Mysql and I can see 700 insert queries , but , when I check the table there is ONLY A SINGLE ROW ENTRY - REST OF 699 ROW OF DATA HAS NOT BEEN INSERTED ....WHY??? Please HELP!! Thanks in advance. Cheers, Vic |
![]() |
| Thread Tools | |
| Display Modes | |
| |