use the below file
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
$csv_file = "mydata.csv"; $csvfile = fopen($csv_file, 'r'); $theData = fgets($csvfile); $i = 0; while (!feof($csvfile)) { $csv_data[] = fgets($csvfile, 1024); $csv_array = explode("\t", $csv_data[$i]); // datas are separated by tab if it is comma then use , instead of \t $insert_csv = array(); $name=$csv_array[0]; $age=$csv_array[1]; $insertqry="insert into tbl_words(name,age) values('$name','$age')"; $insertresult=mysql_query($insertqry,$linkfirst); //$link first is the connection string created for mysql database $i++; } fclose($csvfile); |