I wanted to know if this is the correct way to create a database module, particularly the way the database handle is created and used:
use strict;
use warnings;
use DBI;
my $DB_NAME = 'dancerapp';
my $DB_USER = 'root';
my $DB_PASS = 'root';
sub new {
my $class = shift;
return {}, $class;
}
sub _connect { #use connect_cached() instead?
my $dbh = DBI->connect($DSN, $DB_USER, $DB_PASS) or die $DBI::errstr;
return $dbh;
}
sub getTickets {
my $self = shift;
my $ticket_holder = shift;
my $dbh = $self->_connect;
my $sth = $dbh->prepare("SELECT * FROM table WHERE assigned_to=?");
$sth->execute($ticket_holder);
return $sth->fetchall_hashref;
}
1;
The main purpose of storing all my database queries in one module is to have a single place for them, I'm just concerned with having multiple connections/database handles flying around everywhere