Chinaunix首页 | 论坛 | 博客
  • 博客访问: 40318
  • 博文数量: 26
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 16
  • 用 户 组: 普通用户
  • 注册时间: 2016-12-15 11:11
文章分类

全部博文(26)

文章存档

2019年(1)

2010年(9)

2009年(1)

2008年(9)

2006年(6)

我的朋友

分类:

2010-01-09 14:24:36

Fedora安装Perl DBD-DB2模块

作者:zlj2208

修改日期:20100109

转载请注明转自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

下载地址:~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();


阅读(1566) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~