in reply to Re^2: Singletons, Apache::DBI and MySQL
in thread Singletons, Apache::DBI and MySQL
I doubt that this DESTROY method is called ever. Your $dbhobject is not a blessed reference (just a plain hash ref containing the DBI handle), so this is not really OOP and $classname, $self and so on are a little confusing.sub DESTROY { my $self=shift; if ($dbhobject) { $dbhobject = undef; } }
Update: Okay, maybe I misunderstood. This is the old code you were using (with Apache::DBI)? And it did not reconnect? If so, you were not using Apache::DBI correctly. You have to use "connect" to get a connection, and Apache::DBI will either make a really new connection or just return an alreay open connection. That is transparent to you. What you cannot do is cache the connection Apache::DBI give you in your own singleton object. You have to "connect" every time you want a connection: So instead of
usesub new { my $classname = shift; my $self={}; if ($dbhobject) { $self=$dbhobject } else { $self = bless {}; my $dbh = DBI->connect("DBI:mysql:blah) or die DBI::errstr; $self->{"dbh"} = $dbh; } $self; } sub DBHOBJ { return $dbhobject->{"dbh"}; }
use Apache::DBI; sub DBHOBJ { DBI->connect("DBI:mysql:blah) or die DBI::errstr; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Singletons, Apache::DBI and MySQL
by jbrugger (Parson) on Jan 03, 2005 at 09:45 UTC | |
|
Re^4: Singletons, Apache::DBI and MySQL
by jbrugger (Parson) on Jan 03, 2005 at 09:31 UTC |