On 6/1/07, Jonathan Vanasco <[EMAIL PROTECTED]> wrote:
> When using a MySQL database with modperl 2. I can find lots of docs on
> using DBI, but not much on what is the best practice...

A lot of it is covered here:
http://modperlbook.org/html/ch20_02.html

you also might want to add a cleanup handler that just issues a
rollback, which is something that  perrin often suggests, and I
admittedly blindly follow.  i trust him on those things though :)

Thanks!

Apache::DBI will actually do this for you automatically, but only if
you connect with autocommit turned off.  If you connect with
autocommit on and just turn it off for specific sections (as I do) you
will have to do the safety rollback yourself.

> If I understand Apache::DBI correctly, the DBI->connect picks up a
> cached connection. Is it possible to prepare queries in one place and
> reuse in all the child nodes? E.g. using prepare_cached. If so
> where do
> I put that? In the startup file? In the same module?

i have no idea how to handle the prepared queries, but i will say this;
        i'm pretty sure that in mysql prepared queries work per connection
( i know they do in pgsql ) -- so you wouldn't be able to do it in
startup

Yes, don't do it on startup.  Instead, just use prepare_cached
everywhere you currently use prepare in your code.  It will cache the
statement handle for the next request to benefit from.  If Apache::DBI
notices a stale connection and reconnects, that clears this cache.

- Perrin

Reply via email to