/extremedating/trunk

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/extremedating/trunk
8 by Gustav Hatvigsson
Storted work on the database.
1
<?php
2
/*
3
    ExtremeDating - a Hackathon 2013 project.
4
    Copyright (C) 2013 Gustav Hartvigsson <gustav.hartvigsson@gmail.com>
5
    Copyright (C) 2013 Daniel Johansson <maila@danieljohansson.nu>
6
7
8
    This program is free software: you can redistribute it and/or modify
9
    it under the terms of the GNU Affero General Public License as
10
    published by the Free Software Foundation, either version 3 of the
11
    License, or (at your option) any later version.
12
13
    This program is distributed in the hope that it will be useful,
14
    but WITHOUT ANY WARRANTY; without even the implied warranty of
15
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
    GNU Affero General Public License for more details.
17
18
    You should have received a copy of the GNU Affero General Public License
19
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
20
 
21
 */
22
$db = new PDO("sqlite:./database.db");
23
24
$db->setAttribute(PDO::ATTR_ERRMODE, 
25
                          PDO::ERRMODE_EXCEPTION);
26
27
/*
28
Database design:
12.1.1 by Gustav Hatvigsson
Added a feild to the Useres database.
29
Users(_loginName_, shadow, firstName, surName, city, eMail, profileImage, userType);
8 by Gustav Hatvigsson
Storted work on the database.
30
Resturants(_id_, name, city, phoneNumber, theme);
31
# Theme is if it is, say, a pizzeria or a french resturant or something.
32
Interests(_interest_);
33
FoodType(_foodType_);
10 by Gustav Hatvigsson
Added more tables...
34
UserInterests(-loginName-, -interest-);
35
UserFoodTypes(-loginName-, -foodType-);
8 by Gustav Hatvigsson
Storted work on the database.
36
*/
37
10 by Gustav Hatvigsson
Added more tables...
38
// Create User table
8 by Gustav Hatvigsson
Storted work on the database.
39
$db->exec("
40
  CREATE TABLE IF NOT EXISTS Users(
10 by Gustav Hatvigsson
Added more tables...
41
  loginName varchar(64) PRIMARY KEY,
8 by Gustav Hatvigsson
Storted work on the database.
42
  shadow varchar(64) NOT NULL,
43
  firstName varchar(64) NOT NULL,
10 by Gustav Hatvigsson
Added more tables...
44
  surName varchar(64) NOT NULL,
8 by Gustav Hatvigsson
Storted work on the database.
45
  city varchar(64) NOT NULL,
46
  eMail varchar(64) NOT NULL,
10 by Gustav Hatvigsson
Added more tables...
47
  profileImage blob,
12.1.1 by Gustav Hatvigsson
Added a feild to the Useres database.
48
  userType INTEGER,
10 by Gustav Hatvigsson
Added more tables...
49
  UNIQUE (loginName)
50
  );
51
");
52
13 by Daniel Johansson
fixed Query of names on firstpage
53
//Create Resturants tabel
10 by Gustav Hatvigsson
Added more tables...
54
$db->exec("
55
  CREATE TABLE IF NOT EXISTS Resturants(
56
  id integer PRIMARY KEY,
57
  name varchar(64) NOT NULL,
58
  city varchar(64) NOT NULL,
59
  phoneNumber varchar(64) NOT NULL,
60
  theme varchar(64)
61
  );
62
");
63
64
//Create Interests Table - This table stores the intrests a user may have.
65
$db->exec("
66
  CREATE TABLE IF NOT EXISTS Interests(
67
  interest varchar(64) PRIMARY KEY
68
  );
69
");
70
71
//Create FoodTypes table - this table stores the different types of food thet 
72
// exist.
73
$db->exec("
74
  CREATE TABLE IF NOT EXISTS FoodTypes(
75
  foodType varchar(64) PRIMARY KEY
76
  );
77
");
78
11 by Gustav Hatvigsson
Created relation tables.
79
try {
80
  $db->beginTransaction();
81
  // Relations
82
  $db->exec("
83
    CREATE TABLE IF NOT EXISTS UserIntrests(
84
    loginName varchar(64),
85
    interest varchar(64),
86
    FOREIGN KEY(loginName) REFERENCES Users(loginName),
87
    FOREIGN KEY(interest) REFERENCES Interests(interest),
88
    PRIMARY KEY(loginName, interest)
89
    );
90
  ");
91
  
92
  
93
  $db->exec("
94
    CREATE TABLE IF NOT EXISTS UserFoodTypes(
95
    loginName varchar(64),
96
    foodType varchar(64),
97
    FOREIGN KEY(loginName) REFERENCES Users(loginName),
98
    FOREIGN KEY(foodType) REFERENCES FoodTypes(foodType),
99
    PRIMARY KEY(loginName, foodType)
100
    );
101
  "); 
102
} catch (PDOException $err) {
103
  echo $err;
104
}
105
$db->commit();
8 by Gustav Hatvigsson
Storted work on the database.
106
107
?>