johnnywang has asked for the wisdom of the Perl Monks concerning the following question:

Hi, I've been very happy using Apache::DBI in the mod_perl environment, which provides connection reuse for my mod_perl modules. Recently I discovered the wonderful module Class::DBI, I'm wondering whether Apache::DBI will do similar magic for Class::DBI. My understanding is that Apache::DBI just intercepts all DBI calls for Apache/mod_perl, which presumably will also intercept calls from within Class::DBI, any potential problems (such as transactions/rollbacks)? Aslo, can one use Apache::DBI outside of the Apache/mod_perl environment? e.g., for my own server in POE, can I somehow use Apache::DBI or something similar to provide connection pooling/reuse? Thanks.

Replies are listed 'Best First'.
Re: Apache::DBI and Class::DBI
by PodMaster (Abbot) on Nov 04, 2004 at 09:41 UTC
    which presumably will also intercept calls from within Class::DBI, any potential problems (such as transactions/rollbacks)?
    Same caveats apply as before.
    Aslo, can one use Apache::DBI outside of the Apache/mod_perl environment?
    Looks like no.
    can I somehow use Apache::DBI or something similar to provide connection pooling/reuse?
    Yes, you could UTSL and do exactly what Apache::DBI does (just substitute the mod_perl bits for some POE bits), but since Class::DBI uses Ima::DBI, you don't need to do anything since Ima::DBI already does caching.

    update: a casual google for Apache::DBI and Ima::DBI reveals an important caveat and patch.

    MJD says "you can't just make shit up and expect the computer to know what you mean, retardo!"
    I run a Win32 PPM repository for perl 5.6.x and 5.8.x -- I take requests (README).
    ** The third rule of perl club is a statement of fact: pod is sexy.

Re: Apache::DBI and Class::DBI
by perrin (Chancellor) on Nov 04, 2004 at 13:25 UTC
    PodMaster already pointed you to my post about this on the mod_perl list. The main problem is that if you don't do something like what I show there, you will lose the safety rollback that Apache::DBI does at the end of every request, and this is very important when using a transactional database.

    For persistent connections outside of mod_perl, just use DBI->connect_cached(). Class::DBI already uses this.