On Thu, 22 Jun 2006, Tobias Kremer wrote:
>
> Now I'd like to know if this could cause some sort of trouble because
> I'm making a connection to the database during server startup

If your database happens to be down, you will not be able to start your
web server either.  But you are down one way or the other anyway.

> (I'm also using Apache::DBI)?

Excellent.

> What if My::Structure wants to perform other
> database actions during every apache request? Is it safe to re-use the
> database handle from $self->{_dbh} within My::Structure which got
> initialized during server startup in the _init method? If not, what's a
> better way of doing it?

The better way is to call DBI->connect for every request, and let
Apache::DBI handle the persistance.  I make $dbh a global.

  sub handler {
      $HTML::Mason::Commands::dbh = DBI->connect(...);
      ...
  }

For $structure, you could 1) initialize it with each request, 2) always
access $HTML::Mason::Commands::dbh, or 3) setup $self-{_dbh} as an alias
to $HTML::Mason::Commands::dbh.

If you are in an environment where you are dealing with multiple database
connections, it is more complicated, but you still want to make sure
DBI->Connect on the connection(s) you are using each request, so
Apache::DBI can verify them and reconnect if needed.

~ John Williams



Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Mason-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mason-users

Reply via email to