I want to read .csv file in PHP and put its contents into the database. I wrote the following code:
$row = 1;
$file = fopen(\"qryWebsite.csv\", \"r\");
while
this is not tested... but something like this should do the trick:
$row = 1;
if (($handle = fopen("xxxxxxxxx.csv", "r")) !== FALSE) {
while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
$num = count($data);
echo " $num fields in line $row:
\n";
$row++;
for ($c=0; $c < $num; $c++) {
$blackpowder = $data;
$dynamit = implode(";", $blackpowder);
$pieces = explode(";", $dynamit);
$col1 = $pieces[0];
$col2 = $pieces[1];
$col3 = $pieces[2];
$col4 = $pieces[3];
$col5 = $pieces[5];
mysql_query("
INSERT INTO `xxxxxx`
(`xxx`,`xxx`,`xxx`,`xxxx`,`xxx`)
VALUES
('".$col1."','".$col2."','".$col3."','".$col4."','".$col5."')
");
}
}
}