#! /usr/bin/perl use DBI; my $driver="DBI:mysql"; my $database="perl_test"; my $user="root"; my $host="localhost"; my $passwd="root"; my $rules="alert_rules"; my $dbh = DBI->connect("$driver:database=$database;host=$host;user=$user;password=$passwd") or die "Can't connect: " . DBI->errstr; my $sth=$dbh->prepare("select app_name,receivers from $rules "); $sth->execute() or die "Can't prepare sql statement". $sth->errstr; my $sth=$dbh->prepare("select app_name,receivers from $rules "); $sth->execute() or die "Can't prepare sql statement". $sth->errstr; # 打印获取的数据 while(@recs=$sth->fetchrow_array){ print $recs[0].":".$recs[1]."/n"; } $sth->finish(); $dbh->disconnect();