以下脚本可以循环读取数据库的tr表中的记录。
#!/usr/bin/perl
use strict;
use DBI;
my $dsn="DBI:mysql:demo:localhost:3306";
my $user="root";
my $passwd="mysql56";
my $dbh = DBI->connect($dsn, $user, $passwd);
my $sth = $dbh->prepare("select * from tr where id <50 order by 1 desc");
$sth->execute();
my @arr;
while(@arr = $sth->fetchrow_array()){
print join("|", @arr),"\n";
}
#!/usr/bin/perl
use strict;
use DBI;
my $dsn="DBI:mysql:demo:localhost:3306";
my $user="root";
my $passwd="mysql56";
my $dbh = DBI->connect($dsn, $user, $passwd);
my $sth = $dbh->prepare("select * from tr where id <50 order by 1 desc");
$sth->execute();
my @arr;
while(@arr = $sth->fetchrow_array()){
print join("|", @arr),"\n";
}
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/9606353/viewspace-1086743/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/9606353/viewspace-1086743/