-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmod_karma.php
53 lines (38 loc) · 1.59 KB
/
mod_karma.php
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
46
47
48
49
50
51
52
53
<?php
function karmaup($args) {
include("sqlconfig.php");
$dbh = new PDO('mysql:host=localhost;dbname='.$db,$user,$pass,array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8"));
if(karmalookup($args) == $args." heeft nog geen karma.") {
$query = $dbh->prepare("INSERT INTO karma(name,karma) VALUES (:name,1)");
} else {
$query = $dbh->prepare("UPDATE karma SET karma = karma + 1 WHERE name=:name");
}
$query->bindParam(':name',$args,PDO::PARAM_STR);
$query->execute();
return karmalookup($args);
}
function karmadown($args) {
include("sqlconfig.php");
$dbh = new PDO('mysql:host=localhost;dbname='.$db,$user,$pass,array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8"));
if(karmalookup($args) == $args." heeft nog geen karma.") {
$query = $dbh->prepare("INSERT INTO karma(name,karma) VALUES (:name,-1)");
} else {
$query = $dbh->prepare("UPDATE karma SET karma = karma - 1 WHERE name=:name");
}
$query->bindParam(':name',$args,PDO::PARAM_STR);
$query->execute();
return karmalookup($args);
}
function karmalookup($args) {
include("sqlconfig.php");
$dbh = new PDO('mysql:host=localhost;dbname='.$db,$user,$pass,array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8"));
$query = $dbh->prepare("SELECT karma FROM karma WHERE name=:name");
$query->bindParam(':name',$args,PDO::PARAM_STR);
$query->execute();
if($query->rowCount() > 0) {
$karma = $query->fetchColumn();
return $args." heeft karma: ".$karma;
} else {
return $args." heeft nog geen karma.";
}
}