我正在尝试从Textfile中向表中插入多行。 下面的代码似乎只插入了Textfile的第一行。如何更改它以便循环并插入其余行?
$rwy = "./rwy.txt";
if (file_exists($rwy)) {
sql('TRUNCATE rwy_current');
$array = file($rwy);
foreach ($array as $line) {
$bits = explode("\r\n", $line);
foreach ($bits as $row) {
$col = explode("\t", $row);
sql("INSERT INTO rwy_current (arpt_ident, high_ident, low_ident, high_hdg, low_hdg, length, surface, pcn, he_elev, he_slope, he_tdze, le_elev, le_slope,
le_tdze, he_true_hdg, le_true_hdg, heland_dis, he_takeoff, leland_dis, le_takeoff, cycle_date)
VALUES ('$col[0]', '$col[1]', '$col[2]', '$col[3]', '$col[4]', '$col[5]', '$col[7]', '$col[8]', '$col[13]', '$col[14]', '$col[15]', '$col[30]',
'$col[31]', '$col[32]', '$col[43]', '$col[44]', '$col[46]', '$col[47]', '$col[48]', '$col[49]', '$col[50]')
");
}
}
}
答案 0 :(得分:0)
alter table rwy_current add primary key (arpt_ident, high_ident, low_ident);
解决了它
问题在于数据库;我只有一个主键设置。