http://qs321.pair.com?node_id=11104893

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

I have a bunch of scripts that "use DBI;" . One of the scripts, a particularly database intensive one, says "use Apache::DBI" (which incidentally fail to load).

Is there a difference between Apache::DBI and DBI or can I just change this line to "use DBI" without impact?

Replies are listed 'Best First'.
Re: DBI vs Apache::DBI
by daxim (Curate) on Aug 23, 2019 at 12:36 UTC
    Apache::DBI describes itself as "absolutely transparent". In theory there should be no impact of using plain DBI if there are no forks or threads involved.

    In practice you might find out that the module was required for a particular reason and you might need to touch the code in order to upgrade to the successor DBIx::Connector.

Re: DBI vs Apache::DBI
by 1nickt (Canon) on Aug 23, 2019 at 16:01 UTC

    Hi, are you running your Perl code under mod_perl in an Apache server? That is the only thing that module is designed for unless it's changed a lot. If that's not where your code is running there is no reason to use or load the module.

    Hope this helps!


    The way forward always starts with a minimal test.
Re: DBI vs Apache::DBI
by jcb (Parson) on Aug 23, 2019 at 22:53 UTC

    As other monks have mentioned, Apache::DBI is only for use with mod_perl, where it provides persistent database connections between runs of the script. While it has been a while since I have used mod_perl, I remember that Apache::DBI is supposed to transparently replace DBI when loaded and should be loaded via the server configuration. In other words, scripts should never use Apache::DBI; explicitly, and you should change the offending script to use DBI;.

      Yes, it's running under mod-perl. Should I change it to DBI or DBIx::Connector as the original responder suggested?

        As I understand, Apache:DBI is supposed to be loaded in the mod_perl configuration, not in the script. If Apache::DBI is loaded, use DBI; actually gives you Apache::DBI and its extra feature of connection caching. In all cases, the script should "use DBI;".

        If you want to use DBIx::Connector, you will need to read the documentation and possibly change more than just a use line in your script. I have not used it and I do not know about it.

Re: DBI vs Apache::DBI
by Anonymous Monk on Aug 24, 2019 at 02:08 UTC
    The docs are very careful to explain that Apache::DBI is connection-pooling magic that transparently links into your existing scripts, which use DBI and which should continue to do so. It effectively alters the behavior of DBI. It must be loaded by Apache at startup and at no other time. Follow the instructions exactly.