.csv
파일을 업로드하려고하고 각 행을 mysql
db로 저장하려고합니다. 그래서 .csv
파일의 각 행에 대해 mysql
db에 행을 만들고 싶습니다. 실례지만 내 뜻을 알기를 바랍니다. 그냥 every1 알려PHP + mysql에서 .csv로 여러 행 저장
$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
:
내가 첫 번째 행에서 데이터를 얻을 수 오전, 지금까지 가지고있다 @Greg P의 솔루션은 근무
LOAD DATA LOCAL INFILE '$targetPath' INTO TABLE tableName FIELDS TERMINATED BY ';' (name,url,type,descr)
귀하의 MySQL 테이블 구조는 무엇입니까? – Jeroen