Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

DBI vs Apache::DBI

by DaisyLou (Sexton)
on Aug 23, 2019 at 12:25 UTC ( #11104893=perlquestion: print w/replies, xml ) Need Help??

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 (Deacon) 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 (Abbot) 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 (Hermit) 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.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://11104893]
Approved by marto
Front-paged by haukex
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (8)
As of 2019-09-17 10:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    The room is dark, and your next move is ...












    Results (206 votes). Check out past polls.

    Notices?