in reply to Re: Singletons, Apache::DBI and MySQL
in thread Singletons, Apache::DBI and MySQL
Then i can call it using:package DBH; use strict; use DBI; @ISA = qw(Exporter); @EXPORT_OK = qw(&DBHOBJ); my $dbhobject = new(); sub 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"}; } sub DESTROY { my $self=shift; if ($dbhobject) { $dbhobject = undef; } }
use strict; use DBH qw(&DBHOBJ); my $sth = DBHOBJ()->prepare('select blah from table;'); $sth->execute();
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Singletons, Apache::DBI and MySQL
by Thilosophy (Curate) on Jan 03, 2005 at 09:20 UTC | |
by jbrugger (Parson) on Jan 03, 2005 at 09:45 UTC | |
by jbrugger (Parson) on Jan 03, 2005 at 09:31 UTC |