0
votes

I have a CSV file which contains data seperated with tabs. I need to import the data into a MySQL table which consists of two columns. The first CSV column should go into the first column of the table and similarly for the second.

<?php 
$con=mysql_connect("localhost","root",""); 
mysql_select_db("translation",$con); 
$open=fopen("EH_excel.txt","r"); 
while(($get=fgetcsv($open,1000,","))!==false) { 
  mysql_query("insert into   dictionary(english,croatian)     
  values('".$get[0]."','".$get[1]."')"); 
} 
fclose($open); echo "Import Done."; 
?>

Can anybody help me?

1
Here my coding <?php $con=mysql_connect("localhost","root",""); mysql_select_db("translation",$con); $open=fopen("EH_excel.csv","r"); while(($get=fgetcsv($open,186096,","))!==false) { mysql_query("insert into dictionary(english,croatian)values('".$get[0]."','".$get[1]."')"); } fclose($open); echo "Import Done."; ?> - Shri Gowtham

1 Answers

0
votes

Since what you have is called Tab Delimited Files

This is the way you import it to

SQL

LOAD DATA LOCAL INFILE 'sample.txt' INTO TABLE sample 
FIELDS TERMINATED BY '\t'
OPTIONALLY ENCLOSED BY '' 
ESCAPED BY '' 
LINES TERMINATED BY '\n';