注册会员会员登录

当前位置:首页 > 技术分享

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; #断开数据库连接

    文章评论
    内容:
     
    惠州韦达软件技术服务有限公司:
    电话:15728891693 /18688300180 邮箱:2933839366@qq.com QQ: 2933839366 网址:www.qhscript.com