DB2 with mod_perl not working, works fine in CGI

Posted by Matthew on Stack Overflow See other posts from Stack Overflow or by Matthew
Published on 2010-04-23T00:49:52Z Indexed on 2010/04/23 0:53 UTC
Read the original article Hit count: 499

Filed under:
|
|
|

Hi,

I'm having issues with getting DBI's IBM DB2 driver to work with mod_perl. My test script is:

#!/usr/bin/perl

use CGI;
use Data::Dumper;
use DBI;

$q = CGI->new;
print $q->header;
print $q->start_html();

$dsn = "DBI:DB2:SAMPLE";
$username = "username";
$password = "password";

$dbc = DBI->connect($dsn, $username, $password);
$sth = $dbc->prepare("SELECT * FROM SOME_TABLE WHERE FIELD='SOMETHING'");
$sth->execute();
$row = $sth->fetchrow_hashref();
print "<pre>".$q->escapeHTML(Dumper($row))."</pre>";

print $q->end_html;

This script works as CGI but not under mod_perl. I get this error in apache's error log:

DBD::DB2::dr connect warning: [unixODBC][Driver Manager]Data source name not found, and no default driver specified at /usr/lib/perl5/site_perl/5.8.8/Apache/DBI.pm line 190.
DBI connect('SAMPLE','username',...) failed: [unixODBC][Driver Manager]Data source name not found, and no default driver specified at /data/www/perl/test.pl line 15

First of all, why is it using ODBC? The native DB2 driver is installed (hence it works as CGI).

Running Apache 2.2.3, mod_perl 2.0.4 under RHEL5.

This guy had the same problem as me: http://www.mail-archive.com/[email protected]/msg22909.html But I have no idea how he fixed it. What does mod_php4 have to do with mod_perl?

Any help would be greatly appreciated, I'm having no luck with google.

© Stack Overflow or respective owner

Related posts about mod-perl

Related posts about db2