Import xls data to MYSQL

mysql_connect("localhost","root","") or die("cannot connect");
mysql_select_db("db_name") or die("cannot find database");
$dataSheetFile="sample_csv.csv";
$counter=0;
if (($handle = fopen($dataSheetFile, "r")) !== FALSE) {
while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
$university=htmlentities(trim($data[0]));
$faculty=htmlentities(trim($data[1]));
$research_sub_group=htmlentities(trim($data[2]));
$themenband=htmlentities(trim($data[3]));
$street=htmlentities(trim($data[4]));
$zipcode=htmlentities(trim($data[5]));
$city=htmlentities(trim($data[6]));
$website=htmlentities(trim($data[7]));
$counter++;
mysql_query("INSERT INTO research_sub_group set university='$university', faculty='$faculty', research_sub_group='$research_sub_group', themenband='$themenband', street='$street', zip='$zipcode',city='$city',website='$website'"); }
}
echo "$counter Data has been transferred successfully";

Leave a Reply

Your email address will not be published. Required fields are marked *