forked from chriseng/nestgraph
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathinsert.php
22 lines (19 loc) · 780 Bytes
/
insert.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
<?php
require 'inc/config.php';
require 'inc/class.db.php';
require 'collect.php';
try {
$db = new DB($config);
$data = get_nest_data();
if (!empty($data['timestamp'])) {
if ($stmt = $db->res->prepare("REPLACE INTO data (timestamp, heating, cooling, fan, autoAway, manualAway, leaf, target, current, humidity, updated) VALUES (?,?,?,?,?,?,?,?,?,?,NOW())")) {
$stmt->bind_param("siiiiiiddi", $data['timestamp'], $data['heating'], $data['cooling'], $data['fan'], $data['autoAway'], $data['manualAway'], $data['leaf'], $data['target_temp'], $data['current_temp'], $data['humidity']);
$stmt->execute();
$stmt->close();
}
}
$db->close();
} catch (Exception $e) {
$errors[] = ("DB connection error! <code>" . $e->getMessage() . "</code>.");
}
?>