我的代码如下:
sub new {
my $class = shift;
my $self = bless {}, $class;
$self->initialize();
return $self;
}
sub initialize
{
my $self = shift;
$self->connect();
$self->{'dbh'}
->do("CREATE TABLE IF NOT EXISTS 'settings' (Id INTEGER PRIMARY KEY, Option TEXT, Value TEXT)");
}
sub connect
{
my $self = shift;
$self->{'dbh'} = DBI->connect($self->DSN, "", "", {
RaiseError => 1,
AutoCommit => 1
});
die "Can't connect" unless($self->{'dbh'});
}
sub no_options
{
my$self = shift;
$self->{'dbh'}->prepare("SELECT COUNT(*) as Total FROM settings");
# Here is the problem i get the error here:
# Can't locate object method "execute" via package "DBI::db"
$self->{'dbh'}->execute();
my %row = $self->{'dbh'}->fetchhash_array;
return $row{'Total'};
}
在其他地方我打电话给我的包裹
my $test = Lib::PackageName->new;
print $test->no_options;