Niklas Saers wrote: > ... The perl script below works fine as a CGI from Apache. But when > running it through mod_perl, I get: > [error] Can't locate object method "connect" via package "DBI" > (perhaps you forgot to load "DBI"?) at /home/ab1/test5.pl line 5.\n > ... > use DBI(); > print "Content-type: text/plain\n\n"; > my $dbh=DBI->connect("DBI:mysql:database=db;host=db8.domain.tld", > "user", "pass", {'RaiseError'=>1}); > my $sth=$dbh->prepare("SELECT * FROM Item WHERE Id = 1"); > $sth->execute(); > my $ref=$sth->fetchrow_hashref(); > print "modPerl test5: $ref->{'Item'}";
mod_perl modules aren't written the same way as CGI scripts. Briefly, you need to create a Perl module (e.g. "package"), put the page-generating bits of your code into a subroutine named "handler", and tell Apache to use that module for hits against a given URI. That said, there are also ways to have Apache run Perl CGI scripts using the mod_perl interpreter, which eliminates the process creation overhead of traditional CGI and makes the script run *much* faster. I'm working my way through the Eagle book, which explains it all. You should get a copy: http://www.modperl.com/ I post my code here: http://www.holgerdanske.com/dpchrist/software/index.html David