zoukankan      html  css  js  c++  java
  • perl 执行mysql select 返回多条记录

    [root@dr-mysql01 sbin]# cat t1.pl 
    use DBI;
    my $dbUser='DEVOPS';  
    my $user="root";  
    my $passwd="1234567"; 
    $gp=$ARGV[0];
    my @arr2="";  
    my $dbh  = DBI->connect("dbi:mysql:database=DEVOPS;host=192.168.32.161;port=3306",$user,$passwd) or die "can't connect to database ". DBI-errstr;
    my $hostSql = qq{select  IP,INFO,ENV from  machine_info  where ENV='$gp' }; 
    my ($a1, $a2, $a3,$a4,$a5,$a6,$a7,$a8,$a9);  
    my $selStmt = $dbh->prepare($hostSql);  
    $selStmt->execute();  
    $selStmt->bind_columns(undef, $a1, $a2, $a3);  
    #$selStmt->execute();  
    while( $selStmt->fetch() ){ push (@arr2, "$a1  $a2  $a3
    " );
    };
    print "@arr2 is @arr2
    ";
    You have mail in /var/spool/mail/root
    [root@dr-mysql01 sbin]# perl t1.pl 
    @arr2 is 
    [root@dr-mysql01 sbin]# perl t1.pl 'env-zjtest5'
    @arr2 is  192.168.32.22  haproxy  env-zjtest5
     192.168.32.24  front-end  env-zjtest5
     192.168.32.23  backoffice  env-zjtest5
     192.168.32.25  app  env-zjtest5
     192.168.32.26  zjzc-db  env-zjtest5
     192.168.32.27  pay-db  env-zjtest5
     192.168.32.28  redis  env-zjtest5
     192.168.32.29  nfs  env-zjtest5

  • 相关阅读:
    批处理判断操作系统32位或64位,并注册服务
    VS 2008 快捷键
    VisualSVN Server导入Repository
    C++函数CString类常用函数
    委托和事件
    弄清楚类的访问符
    47-礼物的最大价值
    46-把数字翻译成字符串
    Github使用
    Hash算法相关
  • 原文地址:https://www.cnblogs.com/hzcya1995/p/13350826.html
Copyright © 2011-2022 走看看