package Queries;
use DBI;
use strict;
#we really don't care about this as we are not
#going to instantiate a Queries object. Just its
#children
sub new {
my $proto=shift;
my $class=ref($proto) || $proto;
my $self={};
bless $self,$class;
# We'll just put this here for clarity
$self -> init();
return $self;
}
sub init {
my $self=shift;
#modify this to suit your situation
my $self->{dbh}=DBI->connect('DBI:mysql',"username"
,"password"
);
}
sub execute {
my $self=shift;
my @parms=@_;
return unless $self->{dbh};
return unless $self->{sql};
$self->{sth}=$self->{dbh}->prepare($self->{sql});
}
sub fetchrow_hashref {
my $self=shift;
return unless $self->{sth};
return $self->{sth}->fetchrow_hashref;
}
####
package loadusertable;
use Queries;
use strict;
use vars qw( @ISA );
@ISA=qw(Queries);
sub new {
my $proto=shift;
my $class=ref($proto) || $proto;
my $self={};
bless $self,$class;
$self->init; # we get that from the base class
$self->{sql}="select * from users where id=?";
return $self;
}
####
use Queries;
use strict;
my $q=new loadusertable;
$q->execute(15);
my $row=$q->fetchrow_hashref;
####
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Peter L. Berghold --- Peter@Berghold.Net
"Those who fail to learn from history are condemned to repeat it."