文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>perl dbi 数据库

perl dbi 数据库

时间:2010-08-05  来源:ubuntuer

#! /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

有些我注释的地方,表示是可以有另一种用法


 

相关阅读 更多 +
排行榜 更多 +
我要当超人

我要当超人

休闲益智 下载
幸存者的命运

幸存者的命运

飞行射击 下载
精英战区3d

精英战区3d

飞行射击 下载