连接到informix数据库 - Perl 方式

当前操作系统环境:RHEL 6U4 64bit 安装GCC
数据库版本:Informix 12.10.FC4, CSDK 4.10.FC4

所需要的软件包(包括但不仅限于以下):
perl-5.10.1
perl-DBI-1.609
perl-Test-Pod.noarch
perl-Test-Pod-Coverage.noarch

DBD-informix 下载地址:http://search.cpan.org/~johnl/DBD-Informix-2015.1101/

使用root用户权限,并包含以下环境变量

INFORMIXDIR=/home/informix
INFORMIXSERVER=db31
ONCONFIG=onconfig.db31
PATH=$INFORMIXDIR/bin:$PATH
LD_LIBRARY_PATH=$INFORMIXDIR/lib:$INFORMIXDIR/lib/esql

export INFORMIXDIR INFORMIXSERVER ONCONFIG PATH LD_LIBRARY_PATH

DBI_DBNAME=testdb                    # need exist.
DBD_INFORMIX_DATABASE=testdb        # need exist.
DBD_INFORMIX_USERNAME=informix        # user name
DBD_INFORMIX_PASSWORD=informix        # user pass

export DBI_DBNAME DBD_INFORMIX_DATABASE
export DBD_INFORMIX_USERNAME DBD_INFORMIX_PASSWORD

注:DBD_*开始的参数在编译前必须设置,且指定的数据库必须可以访问

将DBD-Informix-2015.1101.tar.gz解包,并进入编译

# perl Makefile.PL
# make
# make install

如果正确完成,编写一个测试perl文件t.pl

#!/usr/bin/perl -w

use warnings;
use strict;
use DBI;

my $dbh = DBI->connect
          (
              "DBI:Informix:sysmaster",
              'informix',
              'informix'
          );

my $sth1 = $dbh->prepare("select tabid, tabname from systables");
$sth1->execute();

while (my $row = $sth1->fetchrow_hashref())
{

        print sprintf("%-2d %-15s\n", $row->{tabid}, $row->{tabname});

}

$dbh->disconnect();

exit 0;

通过perl t1.pl执行,查看结果

[root@rhel6u4 group]# perl t.pl
1  systables      
2  syscolumns     
3  sysindices     
4  systabauth     
5  syscolauth     
6  sysviews       
7  sysusers       
8  sysdepend      
9  syssynonyms    
10 syssyntable 

标签: none

添加新评论

Free Web Hosting