in reply to OOP design related question.

It depends on the scope of your object. Your idea is okay if it only lasts for the one request. If it lasts longer, that DBI connection might get replaced by a new one. I typically write an accessor method for getting a database handle instead. Some people use a singleton object, which is pretty much the same deal.

Replies are listed 'Best First'.
Re^2: OOP design related question.
by techcode (Hermit) on Sep 09, 2005 at 20:29 UTC
    Yes it only last for one request as I'm using CGI. If I were using mod_perl I believe there is a module that would take care of this, and it would overwrite (dis)connect calls. So I could call it 10 times - and no new connection would be made?
      You're thinking of Apache::DBI. However, if you keep the connection open long enough, the server will break it. That will result in Apache::DBI reconnecting, and that would mean any copies of the old $dbh you have sitting around will not work.