-
Notifications
You must be signed in to change notification settings - Fork 2
/
install_database.php
152 lines (132 loc) · 5.07 KB
/
install_database.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
150
151
152
<?php
require_once "includes/db_functions.php"; //DEBUG - Probably remove
define('DATABASE_EXISTS_ERROR', 1007);
define('TABLE_EXISTS_ERROR', 1050);
function createDatabase($installClean=false)
{
global $conn;
if($installClean)
$conn->query("DROP DATABASE ieee_meeting_tool");
$statuses['Database'] = $conn->query(
"CREATE DATABASE ieee_meeting_tool DEFAULT CHARACTER SET utf8 COLLATE utf8_bin"
);
if($statuses['Database'] === true || $conn->errno === DATABASE_EXISTS_ERROR)
return true;
return false;
}
function createTableStructures($installClean=false)
{
global $conn;
$tableNames = array(
'approved_speaker',
'category',
'category_to_speaker',
'contact_info',
'human',
'proposed_speaker',
'setting',
'url',
'user',
'vote'
);
if($installClean)
foreach($tableNames as $tableName)
$conn->query("DROP TABLE $tableName");
$statuses['TabelApprovedSpeaker'] = $conn->query(
"CREATE TABLE approved_speaker (
id int(10) unsigned NOT NULL AUTO_INCREMENT,
human_id int(10) unsigned NOT NULL,
talk_subject varchar(80) COLLATE utf8_bin NOT NULL,
short_description varchar(600) COLLATE utf8_bin NOT NULL,
extra_info text COLLATE utf8_bin,
upvotes int(10) unsigned NOT NULL DEFAULT '0',
downvotes int(10) unsigned NOT NULL DEFAULT '0',
PRIMARY KEY (id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin"
) || $conn->errno." ".$conn->error;
$statuses['TabelCategory'] = $conn->query(
"CREATE TABLE category (
id int(10) unsigned NOT NULL AUTO_INCREMENT,
name varchar(50) COLLATE utf8_bin NOT NULL,
photo varchar(300) COLLATE utf8_bin DEFAULT NULL,
PRIMARY KEY (id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin ROW_FORMAT=COMPACT"
) || $conn->errno." ".$conn->error;
$statuses['TabelCategoryToSpeaker'] = $conn->query(
"CREATE TABLE category_to_speaker (
approved_speaker_id int(10) unsigned NOT NULL,
category_id int(10) unsigned NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin"
) || $conn->errno." ".$conn->error;
$statuses['TabelContactInfo'] = $conn->query(
"CREATE TABLE contact_info (
id int(10) unsigned NOT NULL AUTO_INCREMENT,
human_id int(10) unsigned NOT NULL,
type varchar(80) COLLATE utf8_bin NOT NULL COMMENT 'eg.: Skype, Facebook, etc',
value varchar(200) COLLATE utf8_bin NOT NULL,
is_public tinyint(1) NOT NULL DEFAULT '1',
PRIMARY KEY (id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin"
) || $conn->errno." ".$conn->error;
$statuses['TabelHuman'] = $conn->query(
"CREATE TABLE human (
id int(10) unsigned NOT NULL AUTO_INCREMENT,
full_name varchar(100) COLLATE utf8_bin NOT NULL,
proffession varchar(100) COLLATE utf8_bin DEFAULT NULL,
photo varchar(300) COLLATE utf8_bin DEFAULT NULL,
PRIMARY KEY (id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin"
) || $conn->errno." ".$conn->error;
$statuses['TabelUser'] = $conn->query(
"CREATE TABLE proposed_speaker (
id int(10) unsigned NOT NULL AUTO_INCREMENT,
human_id int(10) unsigned NOT NULL,
by_user_id int(10) unsigned NOT NULL,
talk_subject varchar(100) COLLATE utf8_bin DEFAULT NULL,
description text COLLATE utf8_bin NOT NULL,
about_speakers_work text COLLATE utf8_bin,
PRIMARY KEY (id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin"
) || $conn->errno." ".$conn->error;
$statuses['TabelSetting'] = $conn->query(
"CREATE TABLE setting (
id int(10) unsigned NOT NULL AUTO_INCREMENT,
title varchar(50) COLLATE utf8_bin NOT NULL,
value varchar(80) COLLATE utf8_bin NOT NULL,
PRIMARY KEY (id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin"
) || $conn->errno." ".$conn->error;
$statuses['TableUrl'] = $conn->query(
"CREATE TABLE url (
id int(10) unsigned NOT NULL AUTO_INCREMENT,
approved_speaker_id int(10) unsigned NOT NULL,
link varchar(300) COLLATE utf8_bin NOT NULL,
PRIMARY KEY (id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin"
) || $conn->errno." ".$conn->error;
$statuses['TableUser'] = $conn->query(
"CREATE TABLE user (
id int(10) unsigned NOT NULL AUTO_INCREMENT,
human_id int(10) unsigned NOT NULL,
is_member tinyint(1) NOT NULL DEFAULT '0',
PRIMARY KEY (id),
UNIQUE KEY user_unique_human_id (human_id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin"
) || $conn->errno." ".$conn->error;
$statuses['TableVote'] = $conn->query(
"CREATE TABLE vote (
user_id int(10) unsigned NOT NULL,
approved_speaker_id int(10) unsigned NOT NULL,
is_upvote tinyint(1) NOT NULL DEFAULT '1'
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin"
) || $conn->errno." ".$conn->error;
foreach($statuses as $key => $status)
if($status!=1 && $status!= TABLE_EXISTS_ERROR)
echo "Error: $status<br>";
}
connect(false, true);
echo "createDatabase: ".(createDatabase()?"OK √":"FAIL ╫")."<br>";
if(!$conn->select_db(DATABASE))
die("ERROR: Couldn't select database ".DATABASE." installation terminated!");
createTableStructures(true);
?>