[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
perl 执行mysql select 返回多条记录
最新推荐文章于 2021-02-06 16:26:00 发布