Genesis perl读取数据库mysql的数据
发布时间:2017-01-07 08:20:00 点击:
#!/bin/perl -w
use strict;
use Tk;
use DBI;
my $dbname = "project_status"; #数据库的名称
my $location = "localhost";
my $port = "3306"; #这是mysql的缺省
my $database = "DBI:mysql:$dbname:$location:$port";
my $db_user = "root";
my $db_pass = "";
my $dbh = DBI->connect($database,$db_user,$db_pass);
my $sql = "SELECT id, week, layer_num FROM project_status_nasupport"; #mysql语句
my $sth = $dbh->prepare($sql);#结果保存在$sth中
$sth->execute() or die "无法执行SQL语句:$dbh->errstr";
while (my @recs=$sth->fetchrow_array) {
print $recs[0].":".$recs[1].":".$recs[2]."\n";
}
$sth->finish;
$dbh->disconnect; #断开数据库连接