use Mysql;
my $dbh = Mysql->connect($dbsvhost, $dbname, $dbuser, $dbpass) or die "Could not connect Mysql Server: $!"; #连接数据库
my $command = "SELECT * FROM $table"; #查询命令
my $sth = $dbh->query($command); #执行
if ($sth) {
while( @rowdata = $sth->fetchrow()) {
#结果保存在 $rowdata[0],$rowdata[1]...中
}
}
-----------
use DBI;
my $dbh = DBI->connect("dbi:mysql:$db:$host", "$db_user", "$db_password") or die "Could not connect Mysql Server: $!"; #连接数据库
my $command = "SELECT * FROM $table"; #查询命令
my $sth = $dbh->prepare($command);
$sth->execute();
if ($sth->rows != 0)
{
my @row;
while (my $row_href = $results->fetchrow_hashref())
{
push(@row, $row_href->{'id'});
}
push (@full_results, @row);
}
$dbh->disconnect;
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/677997/viewspace-664896/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/677997/viewspace-664896/