-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdatabase.php
More file actions
32 lines (26 loc) · 784 Bytes
/
Copy pathdatabase.php
File metadata and controls
32 lines (26 loc) · 784 Bytes
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
<?php
function db() {
global $db_host, $db_user, $db_pass, $db_name;
static $db = null;
if ($db === null) {
$db = new PDO('mysql:host=' . $db_host . ';dbname=' . $db_name, $db_user, $db_pass);
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
}
return $db;
}
function pingStatements() {
static $statements = null;
if ($statements === null) {
$db = db();
$statements = array(
"upsert" => $db->prepare("
INSERT INTO ping (ip, mac, status) VALUES (:ip, NULLIF(:mac, ''), :status)
ON DUPLICATE KEY UPDATE
mac=IF(VALUES(mac) IS NULL, mac, VALUES(mac)),
status=VALUES(status)
"),
"updateStatus" => $db->prepare("CALL update_status(:ip, :mac, :status)")
);
}
return $statements;
}