-
Notifications
You must be signed in to change notification settings - Fork 0
/
db.php
149 lines (125 loc) · 3.87 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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
<?php
ini_set('display_errors',1);
error_reporting(E_ALL);
mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
function db_connect () {
static $connection;
if(!isset($connection)) {
require 'conn.php';
$connection = mysqli_connect($credentials['servername'], $credentials['username'], $credentials['password'], $credentials['dbname']);
mysqli_set_charset ($connection, $credentials['charset'] );
}
return $connection;
};
function db_set () {
$con = db_connect();
$sql = "CREATE DATABASE IF NOT EXISTS dlcr";
mysqli_query(db_connect(), $sql);
$tb_personal_info = "CREATE TABLE IF NOT EXISTS personal_info (
user_id INT AUTO_INCREMENT PRIMARY KEY NOT NULL,
submit_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL,
nascimento DATE NOT NULL,
sexo CHAR(1) NOT NULL,
estado_civil CHAR(1) NOT NULL,
residencia CHAR(2) NOT NULL,
naturalidade CHAR(2) NOT NULL,
escolaridade CHAR(3) NOT NULL,
is_estudante TINYINT(1) NOT NULL,
area_formacao CHAR(1) NULL,
horario_estudo CHAR(1) NULL,
trabalha TINYINT(1) NOT NULL,
profissao VARCHAR(100) NULL,
horario_trab CHAR(1) NULL,
alcool TINYINT(1) NOT NULL,
tabaco TINYINT(1) NOT NULL,
outra_droga TINYINT(1) NOT NULL,
freq_jogo TINYINT(1) NOT NULL,
hora_semana INT(3) NOT NULL,
tempo_vida TINYINT(2) NOT NULL,
tempo_sessao TINYINT(2) NOT NULL,
is_comp TINYINT(1) NOT NULL
)";
$tb_preferencia_jogo = "CREATE TABLE IF NOT EXISTS preferencia_jogo (
prefj_id INT AUTO_INCREMENT PRIMARY KEY,
user_id INT NOT NULL,
ordem TINYINT(1) NOT NULL,
titulo VARCHAR(80) NULL,
hora_semanag INT(3) NULL,
gamep_mode CHAR(1) NULL,
FOREIGN KEY(user_id) REFERENCES user(user_id)
)";
$tb_preferencia_plat = "CREATE TABLE IF NOT EXISTS preferencia_plataforma (
prefp_id INT AUTO_INCREMENT PRIMARY KEY,
user_id INT NOT NULL,
ordem TINYINT(1) NOT NULL,
plataforma CHAR(2) NOT NUll,
FOREIGN KEY(user_id) REFERENCES user(user_id)
)";
$tb_questionario = "CREATE TABLE IF NOT EXISTS questionario (
q_id INT AUTO_INCREMENT PRIMARY KEY,
user_id INT NOT NULL,
q1 TINYINT(1) NOT NULL,
q2 TINYINT(1) NOT NULL,
q3 TINYINT(1) NOT NULL,
q4 TINYINT(1) NOT NULL,
q5 TINYINT(1) NOT NULL,
q6 TINYINT(1) NOT NULL,
q7 TINYINT(1) NOT NULL,
q8 TINYINT(1) NOT NULL,
q9 TINYINT(1) NOT NULL,
FOREIGN KEY(user_id) REFERENCES user(user_id)
)";
$tb_tempo_tarefa = "CREATE TABLE IF NOT EXISTS tempo_tarefa (
tempo_id INT AUTO_INCREMENT PRIMARY KEY,
tempo VARCHAR(50) NOT NULL UNIQUE,
tarefa VARCHAR(50) NOT NULL )";
$tb_results = "CREATE TABLE IF NOT EXISTS results (
result_id INT AUTO_INCREMENT PRIMARY KEY,
user_id INT,
tempo_id INT,
r1 INT DEFAULT 0 NOT NULL,
r2 INT DEFAULT 0 NOT NULL,
r3 INT DEFAULT 0 NOT NULL,
r4 INT DEFAULT 0 NOT NULL,
r5 INT DEFAULT 0 NOT NULL,
r6 INT DEFAULT 0 NOT NULL,
FOREIGN KEY(user_id) REFERENCES user(user_id),
FOREIGN KEY(tempo_id) REFERENCES tempo_tarefa(tempo_id)
)";
mysqli_query($con, $sql);
mysqli_query($con, $tb_personal_info);
mysqli_query($con, $tb_preferencia_jogo);
mysqli_query($con, $tb_preferencia_plat);
mysqli_query($con, $tb_preferencia_jogo);
mysqli_query($con, $tb_questionario);
mysqli_query($con, $tb_tempo_tarefa);
mysqli_query($con, $tb_results);
};
function insert ($query) {
// insert data into the db
// prepared statments
$con = db_connect();
$result = mysqli_query($con, $query);
return $result;
};
db_set();
$insert_tempo_tarefas = "
INSERT INTO tempo_tarefa (`tempo`, `tarefa`)
VALUES
('1 semana', 'Monetario'),
('2 semanas', 'Monetario'),
('1 mes', 'Monetario'),
('6 meses', 'Monetario'),
('1 ano', 'Monetario'),
('3 anos', 'Monetario'),
('10 anos', 'Monetario'),
('1 hora', 'Game'),
('2 horas', 'Game'),
('6 horas', 'Game'),
('1 dia', 'Game'),
('2 dias', 'Game'),
('4 dias', 'Game'),
('7 dias', 'Game')";
//insert ($insert_tempo_tarefas);
//insert ("ALTER TABLE tempo_tarefa AUTO_INCREMENT = 1")
?>