有个mysql的表t(a,b,c)3列。
现在要取得表t的所有记录后,遍历记录,同时更新c列的值,这在perl里要怎么写?# Connect to target DB
my $dbh = DBI->connect("DBI:mysql:database=arabpa");my $sth = $dbh->prepare('SELECT * FROM perl_test') or die $dbh->errstr;
$rv = $sth->execute or die "can't execute the query: $sth->errstr\n";
print "rowscount=$rv\n";
my $table = $sth->fetchall_arrayref or die "$sth->errstr\n";
my($i, $j);
for $i ( 0 .. $#{$table} ) {
for $j ( 0 .. $#{$table->[$i]} ) {
print "$table->[$i][$j]\t";
} print "\n";
} 上面是遍历表的记录,并输出,但不知道要如何更新回数据库中?
谢谢。
现在要取得表t的所有记录后,遍历记录,同时更新c列的值,这在perl里要怎么写?# Connect to target DB
my $dbh = DBI->connect("DBI:mysql:database=arabpa");my $sth = $dbh->prepare('SELECT * FROM perl_test') or die $dbh->errstr;
$rv = $sth->execute or die "can't execute the query: $sth->errstr\n";
print "rowscount=$rv\n";
my $table = $sth->fetchall_arrayref or die "$sth->errstr\n";
my($i, $j);
for $i ( 0 .. $#{$table} ) {
for $j ( 0 .. $#{$table->[$i]} ) {
print "$table->[$i][$j]\t";
} print "\n";
} 上面是遍历表的记录,并输出,但不知道要如何更新回数据库中?
谢谢。
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货