Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
"One of the nicest things about Apache::DBI is that you won't have to modify your existing DBI code to use it. Just add use Apache::DBI; BEFORE the use DBI; in your code, and you're set."

A great article, but this line could potentially be misleading.

The Apache::DBI module is completely transparent; so you don't need to touch your scripts for any reason. Where Apache::DBI actually is defined, is in Apache's configuration file (httpd.conf by default).

Sample mod_perl section of httpd.conf

... # preload these modules PerlModule Apache::Registry; PerlModule CGI; PerlModule Apache::DBI; PerlModule DBI; # startup script PerlRequire /path/to/ ...

If you have a lot of modules to preload, or to use Perl syntax as illustrated above by bttrot, you can define them in the startup script instead. The rule about Apache::DBI going before any other DBI modules still applies.

Just thought I'd clear that up for anyone who read it to mean, "Add use Apache::DBI; to your CGI scripts."

Apache::DBI Potential Traps (UPDATE)

Before everyone runs and starts using Apache::DBI, I'd like to add a cautionary warning.

Don't create a database connection in When Apache forks the connection will be clobbered. Instead Apache::DBI has the safe Apache::DBI->connect_on_init() method (that runs in the PerChildInit phase), though there are caveats to it as well.

Don't use this module if you're logging users into the database individually. For each apache child (pre-forking model) a database connection may be established for each connection string used. This means if you have 10 apache children connecting as 'wwwuser', you'll possibly have 10 connections being kept open. If you log each of say qw(Bill Joe Sally Evan Sue) in individually, a connection for each user in each child might be established. That's 50 open database connections in our tiny example.

More detailed info on these and other issues have been gathered in the new mod_perl and Relational Databases article, be sure to check it out.

See Also

In reply to Re: Tricks with DBI by Arguile
in thread Tricks with DBI by btrott

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or or How to display code and escape characters are good places to start.
Log In?

What's my password?
Create A New User
Domain Nodelet?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (6)
As of 2021-10-21 09:31 GMT
Find Nodes?
    Voting Booth?
    My first memorable Perl project was:

    Results (83 votes). Check out past polls.