繁体   English   中英

使用PHP插入数据库-仅插入一行

[英]Using PHP to Insert Into a Database - only inserting one row

我正在尝试从文本文件向表中插入多行。 下面的代码似乎只插入了文本文件的第一行。 如何更改它,使其循环并插入其余行?

$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]')
           ");
        }
    }
}
alter table rwy_current add primary key (arpt_ident, high_ident, low_ident);

解决了

问题出在数据库中; 我只有一个主键集。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM