-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCategory.pm
47 lines (37 loc) · 950 Bytes
/
Category.pm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package Category;
use DBI;
use Data::Dumper;
use Moose;
extends 'Blog';
my $dbh = Blog->DbConnect();
sub AddNewCategory {
my $content = $_[1];
my $CatName = $_[2];
my $CatLink = $_[3];
my $sth = $dbh->prepare("
INSERT INTO Categories (CatName, CatLink)
VALUES ('$CatName','$CatLink')
"
);
$sth->execute() or die $DBI::errstr;
print "<script>location.href='./ViewCategories.pl' </script>";
$sth->finish();
}
sub DeleteCategory()
{
my $cat = $_[1];
my $sth = $dbh->prepare("
DELETE FROM Categories WHERE CatID = '$cat'
");
$sth->execute() or die $DBI::errstr;
print "<script>location.href='./ViewCategories.pl' </script>";
$sth->finish();
}
sub GetCategories {
my $sth = $dbh->prepare("SELECT CatID, CatName, CatLink FROM Categories");
$sth->execute() or die $DBI::errstr;
my $results = $sth->fetchall_arrayref({});
return($results);
$sth->finish();
}
1;