in reply to One module for both Apache::DBI and DBI?

Actually apache scripts don't use Apache::DBI, or rather not in the sense you are talking about. All of your scripts should use DBI only.

What Apache::DBI does is keep a pool of database connections available so when your script runs multiple times it can reuse the database connection rather than opening a new one every time. This process is transparent to your scripts.

So just continue using DBI like normal and when you need or want higher performance stick 'PerlModule Apache::DBI' in your httpd.conf

  • Comment on Re: One module for both Apache::DBI and DBI?

Replies are listed 'Best First'.
Re: Re: One module for both Apache::DBI and DBI?
by chunlou (Curate) on May 31, 2003 at 23:29 UTC
    Thank tedrek. What you said are correct. (And PerlModule Apache::DBI is in fact how I did it.)

    Maybe my question should have been something more general, like how to dynamically select which modules to use, if possible.

    Like, a regular DB module could probably be used under Apache as well, except that it would not need "use Apache::Reload", although it won't do anything harm if I redundantly include it.

    So, dynamically determining which modules to use at runtime is out of the question?

    Thanks.

      "... a regular DB module could probably be used under Apache as well ..."

      A regular DB module? Are you wanting to create another database handle, in addition to the persistent ones provided by Apache::DBI? One that is not persistent?

      If so then check out recipe 2.13 from the mod_perl Developer's Cookbook. The idea is to use the optional %attr parameter in DBI->connect to allow uncached connections to be created - set dbi_connect_method to the value connect:
      my $dbh = DBI->connect( 'dbi:AnyData:', {dbi_connect_method => 'connect'}, );
      This will not affect the previously cached connections.

      jeffa

      L-LL-L--L-LL-L--L-LL-L--
      -R--R-RR-R--R-RR-R--R-RR
      B--B--B--B--B--B--B--B--
      H---H---H---H---H---H---
      (the triplet paradiddle with high-hat)
      

      Yes you can use one of the other DB modules instead of DBI.

      Apache::Reload is for when you are developing a module and don't want to restart apache everytime you make a change to your module, or when the module's on the server get updated very often.

      It is possible to dynamically select a module to use however you don't need to very often. and you probably don't need to in this case. That being said:

      #Dynamically choose betten Foo and Bar my $type = 'foo'; if ($type eq 'foo') { eval "use Foo"; } else { eval "use Bar"; }

      note that you have to use a quoted string for the eval rather than a block. if you use a block it will always 'use' that module.