perl 测试脚本

作者:zlj2208

修改日期:2010年01月09日

转载请注明转自http://zlj2208.cublog.cn/


1. 系统环境

系统版本:Fedora6 X86_64
DB2版本:DB2 v9.5.0.3
Perl版本: v5.8.8(系统自带)
Perl-DBI版本:perl-DBI-1.52-1.fc6(系统自带)
DBD-DB2版本:DBD-DB2-1.76

2. 安装DBD-DB2

下载地址:http://search.cpan.org/~ibmtordb2/DBD-DB2-1.76/

导入下面环境变量:
根据自己的系统安装的路径,导入相应路径。
export LD_LIBRARY_PATH=/opt/ibm/db2/V9.5/lib64
export DB2_HOME=/opt/ibm/db2/V9.5

安装步骤:
perl Makefile.PL
make
make test
make install

模块安装位置:
cat /usr/lib64/perl5/site_perl/5.8.8/x86_64-linux-thread-multi/auto/DBD/DB2/.packlist
/usr/lib64/perl5/site_perl/5.8.8/x86_64-linux-thread-multi/Bundle/DBD/DB2.pm
/usr/lib64/perl5/site_perl/5.8.8/x86_64-linux-thread-multi/DBD/DB2.pm
/usr/lib64/perl5/site_perl/5.8.8/x86_64-linux-thread-multi/DBD/DB2.pod
/usr/lib64/perl5/site_perl/5.8.8/x86_64-linux-thread-multi/DBD/DB2/Constants.pm
/usr/lib64/perl5/site_perl/5.8.8/x86_64-linux-thread-multi/auto/DBD/DB2/Constants/Constants.bs
/usr/lib64/perl5/site_perl/5.8.8/x86_64-linux-thread-multi/auto/DBD/DB2/Constants/Constants.so
/usr/lib64/perl5/site_perl/5.8.8/x86_64-linux-thread-multi/auto/DBD/DB2/Constants/autosplit.ix
/usr/lib64/perl5/site_perl/5.8.8/x86_64-linux-thread-multi/auto/DBD/DB2/DB2.bs
/usr/lib64/perl5/site_perl/5.8.8/x86_64-linux-thread-multi/auto/DBD/DB2/DB2.so
/usr/share/man/man3/Bundle::DBD::DB2.3pm
/usr/share/man/man3/DBD::DB2.3pm

3. 测试脚本.

1). perl连接远程DB2服务器:
cat perl_connect_to_remote_db2.pl
#!/usr/bin/perl -w
$userid="db2inst1";
$password="passwd";
$db="sample";
$port=50000;
#$hostname="localhost";
$hostname="xxx.xxx.xxx.xxx";
$protocol="tcpip";
$conn_string = "dbi:DB2:DATABASE=$db; HOSTNAME=$hostname; PORT=$port; PROTOCOL=$protocol; UID=$userid; PWD=$password;";

use DBI;
$dbh = DBI->connect ("$conn_string",{RaiseError => 0}) or
die "Can't connect to database $hostname:$db: $DBI::errstr";
my $stmt = "select * from employee";
my $sth = $dbh->prepare($stmt);
$sth->execute();
my $col1;
$sth->bind_col(1,\$col1);
while ($sth->fetch) { print "$col1\n"; }
$sth->finish();
$dbh->disconnect();


2). perl连接本地DB2服务器:
cat perl_connect_to_local_db2.pl
#!/usr/bin/perl -w
$userid="db2inst1";
$password="passwd";
$db="sample";

use DBI;
$dbh = DBI->connect ("dbi:DB2:$db", "$userid", "$password") or
die "Can't connect to $db database: $DBI::errstr";
my $stmt = "select * from employee";
my $sth = $dbh->prepare($stmt);
$sth->execute();
my $col1;
$sth->bind_col(1,\$col1);
while ($sth->fetch) { print "$col1\n"; }
$sth->finish();
$dbh->disconnect()
;
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值