I am trying to upload a .csv file and than save each row to a mysql db. So for each row in the .csv file, I would like to create a row in my mysql db. Excuse my english, but I hope you get what I mean.
I have got so far, that i am able to get the data from the first row:
$path = $targetPath;
$row = 1;
if (($handle = fopen($path, "r")) !== FALSE) {
while (($data = fgetcsv($handle, 1000, ";")) !== FALSE) {
$row++;
$dataEntries[] = $data ;
}
fclose($handle);
} else{
echo("There has been an error parsing ".$csvname);
}
//Everything seems to be okay, we can save it
foreach($dataEntries as $line){
$oName = $line[0];
$oUrl = $line[1];
$oType = $line[2];
$oDescr = $line[3];
//If there is just one row in the csv file, Output: "string"
//If there are more rows, than the output is "stringstring1string2"
echo($oName);
}
UPDATE
Just to let every1 know: @Greg P ´s solution worked great, but I had to add LOCAL to the infile command, so that I could access the csv file that was uploaded to my server:
LOAD DATA LOCAL INFILE '$targetPath' INTO TABLE tableName FIELDS TERMINATED BY ';' (name,url,type,descr)