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 ); };
相关文章推荐
- Web前端初步——Javascript(0)
- 加载js代码
- JS 二维数组排序
- JFreeChart画图+jsp页面显示
- fastjson生成json时Null属性不显示
- JSONP跨域处理实例
- JavaScript 进阶学习 7 DOM对象,控制HTML元素
- JSON
- javascript设计模式——单例模式
- JSTL常用标签
- javascript设计模式——工厂模式
- js 当前日期处理 获取
- JS字符串与汉字的字节获取
- js中双等号与三等号的区别
- js校验(正则 地址 身份证号)
- javascriptw文件操作(全套)
- ejs模板中的四种表达式输出形式
- 原生JS封装Ajax插件(同域、jsonp跨域)
- js获取cookie
- JavaScript 进阶学习 6 浏览器对象