forked from pokepark/PokemonRaidBot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinsert_gym.php
59 lines (55 loc) · 1.68 KB
/
insert_gym.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
54
55
56
57
58
59
<?php
/**
* Insert gym.
* @param $gym_name
* @param $latitude
* @param $longitude
* @param $address
*/
function insert_gym($name, $lat, $lon, $address)
{
global $dbh;
// Build query to check if gym is already in database or not
$stmt = $dbh->prepare("
SELECT COUNT(*) AS count
FROM gyms
WHERE gym_name = :name");
$row = $stmt->fetch();
// Gym already in database or new
if (empty($row['count'])) {
// Build query for gyms table to add gym to database
debug_log('Gym not found in database gym list! Adding gym "' . $name . '" to the database gym list.');
$stmt = $dbh->prepare("
INSERT INTO gyms
SET lat = :lat,
lon = :lon,
gym_name = :name,
address = :address
");
$stmt->execute([
'lat' => $lat,
'lon' => $lon,
'name' => $name,
'address' => $address
]);
} else {
// Update gyms table to reflect gym changes.
// TODO(@Artanicus): using gym name as the selector is bad and doesn't allow updating gym name
debug_log('Gym found in database gym list! Updating gym "' . $name . '" now.');
$stmt = $dbh->prepare("
UPDATE gyms
SET lat = :lat,
lon = :lon,
gym_name = :name,
address = :address
WHERE gym_name = :name
");
$stmt->execute([
'lat' => $lat,
'lon' => $lon,
'name' => $name,
'address' => $address
]);
}
}
?>