免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2147 | 回复: 2
打印 上一主题 下一主题

perl 数据库取值的问题 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2003-10-07 13:54 |只看该作者 |倒序浏览
my $dbh = DBI->;connect( "DBI:ODBCx","xx","xx" ) or die $DBI::errstr;
my $sql = "SELECT AVG(row) as temp-output FROM table-t where time between 10-1 and 10-30" ;
my $sth = $dbh->;prepare( $sql );
$sth->;execute;

现在我有一个平均值在temp-output里,我要如何把这个变量取出来?
我只知道
my $table = $sth->;fetchall_arrayref or die "$sth->;errstr\n";
my($i, $j);
for $i ( 0 .. $#{$table} )
   { for $j ( 0 .. $#{$table->;[$i]} )
..........................
这样是取table-t里的值,但是如何取temp-output里的值呢?
谢谢

论坛徽章:
0
2 [报告]
发表于 2003-10-07 15:37 |只看该作者

perl 数据库取值的问题

取一个值可以用fetchrow方法,例子:

my $sth = $dbh->;prepare("select 1 from dual";
$sth->;execute;
my ($test) = $sth->;fetchrow();

$sth->;finish;


$sth 所有的方法如下:
execute()
fetchrow()
fetchrow_array()
fetchrow_arrayref()
fetchrow_hashref()
fetchall_arrayref($slice, $max_rows)
fetchall_hashref($keyfield, ...)
finish()
bind_param($num, $name, options)
can($method_name)

论坛徽章:
0
3 [报告]
发表于 2003-10-08 10:07 |只看该作者

perl 数据库取值的问题


  1. ......
  2. while(@rows = $sth->;fetchrow_array)
  3. {
  4.         #foreach(@rows)
  5.         #{
  6.         #        print "$_\t";
  7.         #}
  8.            print $rows["host"];
  9.         print $rows["user"];
  10.         print "\n";
  11. }
  12. ......
复制代码
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP