A Database Example
- Raising exceptions – the easy way
my $attr = { AutoCommit => 0, RaiseError => 1, PrintError => 0 };
my $dsn = 'dbi:Pg:dbname=products';
sub get_categories_by_mgr {
my($prod_mgr_id) = @_;
my $dbh = DBI->connect($dsn, $user, $pswd, $attr);
my $sql = 'SELECT * FROM prod_category WHERE prod_mgr_id = ?';
my $sth = $dbh->prepare($sql);
$sth->execute($prod_mgr_id);
my @categories;
while(my $row = $sth->fetchrow_arrayref) {
push @categories, $row;
}
$dbh->disconnect;
return \@categories;
}