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\n" );
};
print "\@arr2 is @arr2\n";
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
上一篇:C语言基础(4)-原码,反码,补码及sizeof关键字


下一篇:Python pip源更改