-
Notifications
You must be signed in to change notification settings - Fork 0
/
_db.php
42 lines (33 loc) · 1.22 KB
/
_db.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
<?php
$db_exists = file_exists("daypilot.sqlite");
$db = new PDO('sqlite:daypilot.sqlite');
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
if (!$db_exists) {
//create the database
$db->exec("CREATE TABLE IF NOT EXISTS events (
id INTEGER PRIMARY KEY,
name TEXT,
start DATETIME,
end DATETIME,
resource VARCHAR(30))");
$messages = array(
array('name' => 'Event 1',
'start' => '2018-05-09T00:00:00',
'end' => '2018-05-09T10:00:00',
'resource' => 'B')
);
$insert = "INSERT INTO events (name, start, end, resource) VALUES (:name, :start, :end, :resource)";
$stmt = $db->prepare($insert);
$stmt->bindParam(':name', $name);
$stmt->bindParam(':start', $start);
$stmt->bindParam(':end', $end);
$stmt->bindParam(':resource', $resource);
foreach ($messages as $m) {
$name = $m['name'];
$start = $m['start'];
$end = $m['end'];
$resource = $m['resource'];
$stmt->execute();
}
}
?>