You can get a global handle through a closure. That's more or less ok in OO since it's a method which accesses the handle ;-)
I used an empty prototype to give perl a hint when My::dbh is called without parens.package My; use DBI; { my $dbh = DBI::connect( . . .); # add error handling sub dbh () { $dbh } } # call up the handle with My::dbh(). # You don't need to import anything from DBI unless you # want to see or modify its globals package My::Collection; # . . .
Note that sharing a dbi connection between objects will break for threaded or forked code. In those cases a private handle should be preferred.
After Compline,
Zaxo
In reply to Re: How to share DBI connections between objects?
by Zaxo
in thread How to share DBI connections between objects?
by blahblah
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |