in reply to Re: Problem managing persistent database connections in modules
in thread Problem managing persistent database connections in modules

Could you give an example of where you call MyProject::DBH->get_dbh in a module and where you store the database handle? I.e., do you call it from the constructor then store the database handle in the object as instance data, or do you call it from each object method that needs a database handle?
  • Comment on Re: Re: Problem managing persistent database connections in modules

Replies are listed 'Best First'.
Re: Re: Re: Problem managing persistent database connections in modules
by mfriedman (Monk) on Jul 29, 2002 at 23:24 UTC
    In that project, I had each class which needed access to the DB call MyProject::DBH->get_dbh in its constructor and store the returned database handle in the instance data. Then, it's available for each method that needs it in $self->{'dbh'}.

    You could just as easily make the DBH a package variable, but doing it this way seemed "neater" despite the increaed number of calls to get_dbh.