You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Levon Barker <le...@cam.ca> on 2003/07/25 20:55:17 UTC

Database Connections & Global Variables

Hello,

I have a question. 

If I have a $dbh global variable in a particular module that I 'use'. I know
that Apache::DBI will give a cached connection to the module to use.

But what if I do something like $dbh->commit();

Is it possible that I am committing data for another session by accident?

Any thoughts on this are appreciated. (Including RTFM (but tell me where in
the FMTR))

Cheers,
Levon Barker

Re: Database Connections & Global Variables

Posted by Perrin Harkins <pe...@elem.com>.
On Fri, 2003-07-25 at 14:55, Levon Barker wrote:
> If I have a $dbh global variable in a particular module that I 'use'. I know
> that Apache::DBI will give a cached connection to the module to use.

There is no need to use a global.  Apache::DBI caches it for you.  If
you put it in a global, then Apache::DBI doesn't get to do its ping.

> But what if I do something like $dbh->commit();
> 
> Is it possible that I am committing data for another session by accident?

At the end of each request, Apache::DBI issues a rollback for any
uncommitted transactions.  That means that the only things that could be
committed are things that you did earlier in the current request.  And
remember, these are not shared between processes, so there's no need to
be worried about interference from other requests.

- Perrin