Perl database interface for IBM DB2 for z/OS, DB2 for Linux/Unix/Windows (LUW), and DB2 for i (AS/400).
DBD::DB2 enables Perl applications to connect to, query, and interact with IBM DB2 databases. This repository provides both source code and pre-compiled Windows binaries (DLLs for ActivePerl and Strawberry Perl) to simplify installation and avoid compilation issues with the DB2 CLI Driver.
Windows Users (Easiest): Use pre-compiled binaries from the
Windows_Binaryfolder
CPAN Users: Runcpanm install DBD::DB2
Developers: Build from source (see Installation section)
Perl version 5.8 or later (tested up to 5.40) Confirm by typing in command prompt:
perl -v
DBI Module version 1.21 or later (Perl Database Interface) Install with:
cpanm install DBI
IBM DB2 Application Development Client version 7.2 or later
- Included with DB2 Personal Developer's Edition and DB2 Universal Developer's Edition
- Download from IBM DB2 Support
Pre-compiled DBD::DB2 DLLs are provided in the
Windows_Binaryfolder to avoid compilation issues with the CLI Driver.
-
Locate your Perl installation:
perl -v
-
Download the appropriate binary from
Windows_Binaryfolder:- Choose folder matching your Perl distribution (ActivePerl or Strawberry Perl)
- Select version matching your Perl version
-
Copy files to Perl library directory:
copy DB2.dll "C:\Perl\site\lib\auto\DBD\DB2\" copy DB2.pm "C:\Perl\site\lib\DBD\"
(Adjust path based on your Perl installation)
-
Verify installation:
perl -e "use DBD::DB2; print qq{Success\n};"
Prerequisites: MSVC or MinGW C++ Compiler must be installed
-
Navigate to the repository directory:
cd path\to\perl_DBD-DB2 -
Run build commands:
perl Makefile.PL nmake nmake test nmake install
-
Set environment variables:
export DB2_HOME=<path-to-DB2-CLI-driver>/clidriver export PERL5LIB=~/lib/perl5:$DB2_HOME/perl:$HOME/DBD-DB2-<version>/tests:$HOME/DBD-DB2-<version>/Constants
-
Build and install:
perl Makefile.PL make make test make install
perl Makefile.PL PREFIX=~/lib/perl5
make
make test
make installPrerequisites: Perl 5.8+, DB2 CLI v10.5+, xlccmp 13.1.3+
-
Extract required files to
/tmp/perl:mkdir -p /tmp/perl cd /tmp/perl # Extract: v10.5fp11_aix64_odbc_cli_32.tar, DBI-1.643.tar, DBD-DB2-<version>.tar
-
Install DBI module:
cd DBI-1.643 perl Makefile.PL make make test make install
-
Install DBD::DB2:
cd ../DBD-DB2-<version> export DB2_HOME=/tmp/perl/odbc_cli_32/clidriver export PERL5LIB=/usr/opt/perl5/lib/site_perl/5.28.1/aix-thread-multi:$DB2_HOME/perl:$(pwd)/tests:$(pwd)/Constants perl Makefile.PL make make test make install
Set
DB2_USERandDB2_PASSWDas environment variables. Configuration can also be provided intests/connection.pl.
-
Edit
tests/connection.pl:$USERID="your_db2_username"; $PASSWORD="your_db2_password"; $PORT=50000; $HOSTNAME="your_db_server"; $DATABASE="your_database_name"; $PROTOCOL="TCPIP";
-
Run test suite:
perl run-tests.pl
Create test_db2.pl:
#!/usr/bin/perl
use strict;
use warnings;
use DBI;
my $dbh = DBI->connect('dbi:DB2:database=SAMPLE', 'userid', 'password')
or die "Connection failed: $DBI::errstr";
print "Connected successfully!\n";
my $sth = $dbh->prepare("SELECT * FROM SYSCAT.TABLES FETCH FIRST 5 ROWS ONLY");
$sth->execute() or die "Query failed: $DBI::errstr";
while (my $row = $sth->fetchrow_hashref()) {
print "Table: ", $row->{TABNAME}, "\n";
}
$sth->finish();
$dbh->disconnect();Run with:
perl test_db2.pl| Issue | Solution |
|---|---|
| "Can't find module DBD::DB2" | Ensure DBI is installed first: cpanm install DBI |
| "DB2_HOME not set" | Set environment variable pointing to DB2 CLI driver installation |
| Compilation errors with sqlext.h | Use pre-compiled Windows binaries instead of building from source |
| Permission denied during install | Run with sudo or use PREFIX=~/lib/perl5 for user-level installation |
| Test connection fails | Verify credentials in tests/connection.pl and ensure DB2 server is running |
- CAVEATS - Platform-specific solutions and workarounds
- TESTING_GUIDE.md - Comprehensive testing procedures
- TEST_GAP_ANALYSIS.md - Test coverage details
- Technical Support: IBM DB2 service agreements
- DB2 Documentation: IBM DB2 Info Center
- DB2 Perl Resources: IBM DB2 Perl Page
| List | Purpose |
|---|---|
| dbi-announce@perl.org | Announcements |
| dbi-dev@perl.org | Developer discussions |
| dbi-users@perl.org | User help & questions |
Subscribe: Send email to <listname>-subscribe@perl.org or visit lists.perl.org
- Project: GitHub: perl_DBD-DB2
- Report Issues: Use GitHub Issues feature
| File | Content |
|---|---|
| CAVEATS | Important platform-specific information and workarounds |
| DB2.pod | Example Perl scripts for using DBD::DB2 |
| TESTING_GUIDE.md | Comprehensive testing procedures and guidelines |
| TEST_GAP_ANALYSIS.md | Test coverage details and limitations |
| MISSING_TEST_CASES.md | Scenarios not yet covered by tests |
See LICENSE file for details.
Last Updated: February 2026
For latest information, visit: GitHub Repository