-
Notifications
You must be signed in to change notification settings - Fork 1
/
biome.php
executable file
·43 lines (32 loc) · 1.32 KB
/
biome.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
<?php
function get_biome_contents($db){
$contents = [];
$statement = $db->prepare("SELECT name,color,characters FROM biome ORDER BY id ASC");
$statement->execute();
while($row = $statement->fetch()){
$contents[$row["name"]] = array("color"=>"#".$row["color"], "character"=>$row["characters"]);
}
return $contents;
}
function determine_biome($db, $text){
$statement = $db->prepare("SELECT biome_id FROM biome_words WHERE INSTR(?, word) ORDER BY biome_id ASC");
$statement->execute([$text]);
$info = $statement->fetch();
if ($info){
return $info["biome_id"];
}
else{
return get_default_biome($db);
}
}
function get_biome_by_name($db, $name){
$statement = $db->prepare("SELECT id FROM biome WHERE name=? ORDER BY id ASC");
$statement->execute([strtoupper($name)]);
return ($row = $statement->fetch()) ? $row["id"] : get_default_biome($db);
}
function get_default_biome($db){
$statement = $db->prepare("SELECT id FROM biome ORDER BY id ASC");
$statement->execute();
return $statement->fetch()["id"];
}
?>