At 01:26 PM 8/23/2001 -0700, Benjamin Trott wrote:
> > I haven't read the entire thread, so forgive me if I'm restating. But there
> > are reasons for sharing DB connections (and reasons not to). In the case of
> > MySQL and getting messages about active statement handles, that's because
> > you're disconnecting the DBH. If you are in a shared connection enviroment
> > with MySQL, you are winning. Since you don't have to worry about things 
> like
> > transactions and rolling back somebody elses changes. All you need to do is
> > finish() your statement handled when you are finished with them:
> >
> > $sth->finish;
> >
> > This will prevent the errors you are seeing and will allow you to keep the
> > shared DB connection. A shared connection is usefull for efficiency, since
> > creating a connection may be expensive.
>
>No, I called finish on all of my statement handles; that is not the reason
>for the errors I got. The behavior I am talking about *only occurs* for me
>when I open a connection in the Apache parent. Then this same DB connection
>is shared across all of the Apache children, and Strange Things occur.

I may be off track on this, but I had some difficulty using database handles
in a perl script that opened the db handle in the parent then forked off a 
number of
children until I did the following in the children, which basically eliminated
sharing of the handle:

       $dbhparent->{InactiveDestroy} = 1;
       $dbhparent = undef;

This was under command line perl, not mod_perl, with mysql as the database,
and using DBI only, not Apache::DBI.

The DBI manpage says:

        ""InactiveDestroy"" (boolean)
            This attribute can be used to disable the database
            engine related effect of DESTROYing a handle (which
            would normally close a prepared statement or discon­
            nect from the database etc).

            For a database handle, this attribute does not disable
            an explicit call to the disconnect method, only the
            implicit call from DESTROY.

            This attribute is specifically designed for use in
            Unix applications that "fork" child processes. Either
            the parent or the child process, but not both, should
            set "InactiveDestroy" on all their shared handles.
            Note that some databases, including Oracle, don't sup­
            port passing a database connection across a fork.

--
Matthew Pressly

> >> I am sorry but this topic is confusing me... Are you saying that
> >> persistent DB connection objects are bad?
> >
> > It sounds like that, doesn't it?
>
>Well, I'm sorry if it sounds like that, but that's not what I'm saying. :)
>
>I am merely echoing Perrin's statement that opening a shared connection in
>the parent is bad, because this connection is then shared between *all* of
>the children. You don't want this. You want one connection per child, not
>one connection shared between all Apache children. The latter *will* cause
>problems.
>
>bye,
>Ben

Reply via email to