您的位置:首页 > Web前端 > JavaScript

mojo 接口返回键值对的json格式

2016-05-03 12:55 381 查看
my $c = shift;
use DBI;
my %hash=();
my $dbUser='zabbix';
my $user="root";
my $passwd="1234567";
my $dbh  = DBI->connect("dbi:mysql:database=$dbUser;host=192.168.32.xx;port=3306",$user,$passwd) or die "can't connect to database ". DBI-errstr;
my $hostSql = qq{ select hostid,name  from hosts  where hostid in ('10001','10081','10050') };
my ($a1, $a2, $a3,$a4,$a5,$a6,$a7,$a8,$a9);

my $selStmt = $dbh->prepare($hostSql);
$selStmt->execute();
$selStmt->bind_columns(undef, \$a1, \$a2);
while( $selStmt->fetch() ){
print "\$a1 is $a1\n";
print "\$a2 is $a2\n";
$hash{$a1}=$a2;
};
print %hash;
print "\n";
$c->render(json =>  \%hash );
};

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: