-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig.php
More file actions
133 lines (133 loc) · 3.99 KB
/
Copy pathconfig.php
File metadata and controls
133 lines (133 loc) · 3.99 KB
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
<?php
/**
* This file is a part of Fedea Project (https://github.com/khasfedea/FedeaProject).
* Copyright (C) 2021 Furkan Mudanyali, Team FEDEA.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
// Define database credentials and stuff
define('DB_SERVER', 'localhost');
define('DB_USERNAME', 'fedea');
define('DB_PASSWORD', 'test');
define('DB_NAME', 'khas1');
// Attempt connecting
$link = mysqli_connect(DB_SERVER, DB_USERNAME, DB_PASSWORD, DB_NAME);
// Catch fire if you cant
if($link === false){
die("ERROR: Could not connect. " . mysqli_connect_error());
}
/*
// Create tables if they dont exist
$queryArray = [
"
CREATE TABLE IF NOT EXISTS users(
id INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
student_id VARCHAR(50) NOT NULL UNIQUE,
firstName VARCHAR(50) NOT NULL,
lastName VARCHAR(50) NOT NULL,
avatarSrc VARCHAR(255) DEFAULT 'img/avatars/default.jpg',
privacy BOOL DEFAULT 1,
email VARCHAR(75) NOT NULL UNIQUE,
dateOfBirth DATETIME NULL,
password VARCHAR(255) NOT NULL,
branch VARCHAR(128) NULL,
bio VARCHAR(500) NULL,
created_at DATETIME DEFAULT CURRENT_TIMESTAMP
);
",
"
CREATE TABLE IF NOT EXISTS friendship(
id INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
firstUser VARCHAR(50) NOT NULL,
friendedUser VARCHAR(50) NOT NULL
);
",
"
CREATE TABLE IF NOT EXISTS friendship_req(
id int not null primary key auto_increment,
target VARCHAR(50) not null,
destination VARCHAR(50) not null
);
",
"
CREATE TRIGGER befriend_yourself
AFTER INSERT ON users
FOR EACH ROW
INSERT INTO friendship(firstUser, friendedUser) VALUES(NEW.student_id, NEW.student_id);
",
"
CREATE TABLE IF NOT EXISTS admin(
id INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
admin_id VARCHAR(50) NOT NULL UNIQUE);
",
"
CREATE TABLE IF NOT EXISTS posts(
id INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
poster_id VARCHAR(50) NOT NULL,
post VARCHAR(500) NOT NULL,
image VARCHAR(255) NULL,
timestamp DATETIME DEFAULT CURRENT_TIMESTAMP
);
",
"
CREATE TABLE IF NOT EXISTS messages(
id INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
sender_id VARCHAR(50) NOT NULL,
receiver_id VARCHAR(50) NOT NULL,
message VARCHAR(500) NOT NULL,
timestamp DATETIME DEFAULT CURRENT_TIMESTAMP
);
",
"
CREATE TABLE IF NOT EXISTS announcements(
id INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
announcer_id VARCHAR(50) NOT NULL,
announcement VARCHAR(500) NOT NULL,
image VARCHAR(255) NULL,
timestamp DATETIME DEFAULT CURRENT_TIMESTAMP
);
",
"
CREATE TABLE IF NOT EXISTS comments(
id INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
commenter_id VARCHAR(50) NOT NULL,
comment VARCHAR(500) NOT NULL,
post_id VARCHAR(500) NOT NULL,
timestamp DATETIME DEFAULT CURRENT_TIMESTAMP
);
",
"
CREATE TABLE IF NOT EXISTS liked_posts(
id INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
liker VARCHAR(50) NOT NULL,
liked VARCHAR(50) NOT NULL
);
",
"
CREATE TABLE IF NOT EXISTS liked_comments(
id INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
liker VARCHAR(50) NOT NULL,
liked VARCHAR(50) NOT NULL
);
"
];
foreach ($queryArray as &$query){
if($stmt = mysqli_prepare($link, $query)) {
mysqli_stmt_execute($stmt);
} else {
echo "Something went wrong for some reason.\n\n";
die("<pre>".mysqli_error($link).PHP_EOL.$query."</pre>");
}
} unset($query); // not unsetting $query produces undefined behaviour.
*/
?>