Don't ask to ask, just ask | |
PerlMonks |
Re: Modules and DBIby Revelation (Deacon) |
on Nov 10, 2002 at 20:55 UTC ( [id://211794]=note: print w/replies, xml ) | Need Help?? |
If you're asking 'how can I pass around a database handle, so I don't have to generate it repeatedly,' there are a couple ways:
The simplest of them would be to create a singleton class, which holds the database handle like so: And connect by doing MyStateManagement::DBI::Singleton->connect(); the same way you would connect with DBI. Assuming you use one database handle for the whole package, subsequent connects will use the same connection, and will not regenerate the connect; however, you could change the singleton class to check to see if the connect string was the same, and create some sort of connect hash, if there were multiple connections (or you could just specify the connection by a number, or something of that sort.) The alternative would be to just pass around your database handle through the subroutines. Gyan Kapur gyan.kapur@rhhllp.com
In Section
Seekers of Perl Wisdom
|
|