i want to import csv file into mysql.. something like:
load data local infile 'uniq.csv' into table tblUniq
fields terminated by ','
enclosed by '"'
lines terminated by '\n'
(uniqName, uniqCity, uniqComments)
but column names in csv and that in database table are different what should i do?
i want to do it programmatically..
解决方案
You can create a script to parse your csv file and to put the data into db.
Something like:
$path = "yourfile.csv";
$row = 1;
if (($handle = fopen($path, "r")) !== FALSE) {
while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
$row++;
$data_entries[] = $data ;
}
fclose($handle);
}
// this you'll have to expand
foreach($data_entries as $line){
$sql = "INSERT INTO ..."
$db->execute($line);
}