我在 Perl 中有 3 个不同的数组(即 A、B 和 C)。现在,我在 mysql 中有一个表,它也有 3 个字段。
我想要做的是在mysql表的第一个字段中获取数组A的所有内容,在第二个字段中获取数组B的内容,依此类推。我尝试使用 foreach 循环执行此操作,但它适用于第一个数组,但不会为第二个和第三个数组插入任何内容。
使用的代码如下:
foreach my $a (@a) {
my $sql = "insert into es(a) VALUES(\"$a\")";
my $sth = $dbh->prepare($sql);
$sth->execute or die "SQL Error: $DBI::errstr\n";
}
foreach my $b (@b) {
my $sql = "insert into es(b) VALUES(\"$b\")";
my $sth = $dbh->prepare($sql);
$sth->execute or die "SQL Error: $DBI::errstr\n";
}
第三个也是如此。表的 a 列已正确填充,但表中的 b 列和 c 列没有数据。我究竟做错了什么。