#! /usr/bin/perl -w
use strict;
use DBI; my $Db="test"; my $DbHost="192.168.83.137"; my $DbPort=3306; my $DbUser="root"; my $DbPwd='123456';
my $DbH=DBI->connect("dbi:mysql:database=$Db; host=$DbHost;port=$DbPort",$DbUser,$DbPwd,{PrintError=>0, RaiseError=>0,AutoCommit=>0}) or die "connect to db failed...\n"; my $StrSql='select uin, nickName from info where uin = ?'; my $Sth=$DbH->prepare($StrSql);
my $i = 0; my $Result; my $uin; my $nickName; my @a = qw( 1 2 3 4 ); foreach $i ( qw(1 2 3 4) ){ $Sth->bind_param(1, $i); $Result=$Sth->execute(); # $Result=$Sth->execute($i);
die "undefined" if (!defined $Result);
$Sth->bind_columns(undef, \$uin, \$nickName); # while(($uin,$nickName )=$Sth->fetchrow_array){
while($Sth->fetch()){ print "$uin, $nickName\n"; } } $Sth->finish; $DbH->disconnect;
|
1, zj1
2, kenthy
3, jeremy
4, jimmy
有些我注释的地方,表示是可以有另一种用法
阅读(1319) | 评论(0) | 转发(0) |