This repository has been archived by the owner on Mar 26, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
/
ci.php
144 lines (140 loc) · 5.86 KB
/
ci.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
<?php
/**
* ___ ____ _
* / _ \ / ___| | __ _ ___ ___ _ __ ___ ___ _ __ ___
*| | | | | | |/ _` / __/ __| '__/ _ \ / _ \| '_ ` _ \
*| |_| | |___| | (_| \__ \__ \ | | (_) | (_) | | | | | |
* \__\_\\____|_|\__,_|___/___/_| \___/ \___/|_| |_| |_|
* 青草课堂 - ci.php
* Copyright (c) 2015 - 2019.,QCTech ,All rights reserved.
* Created by: QCTech
* Created Time: 2019-02-04 - 16:15
*/
if (!isset($_SERVER['SHELL'])) {
http_response_code(403);
die('Access Denied');
}
mysqli_report(MYSQLI_REPORT_STRICT);
// ========================//
// 数据库配置 //
// ========================//
$Config["database"]["address"] = "127.0.0.1"; //数据库地址
$Config["database"]["port"] = 3306; //数据库端口
$Config["database"]["username"] = "root"; //数据库账号
$Config["database"]["password"] = ""; //数据库密码
$Config["database"]["name"] = "edu"; //数据库名称
// 创建连接
$conn = new mysqli($Config["database"]["address"], $Config["database"]["username"], $Config["database"]["password"],
$Config["database"]["name"]);
// 检查连接
if ($conn->connect_error) {
die( "Error 数据库连接失败: " . $conn->connect_error);
}
mysqli_set_charset($conn,"utf8");
//设置编码
$conn->query("ALTER DATABASE `". $Config["database"]["name"] ."` COLLATE utf8_swedish_ci");
//qc_group 用户组表
$conn->query("CREATE TABLE `qc_group` (
`gid` tinyint NOT NULL COMMENT '用户组ID',
`name` tinytext NOT NULL COMMENT '用户组名称'
);");
$conn->query("ALTER TABLE `qc_group`
ADD PRIMARY KEY `gid` (`gid`);");
//qc_group 默认数据
$qc_group = [
0 => '临时封禁',
1 => '学生',
2 => '教师',
3 => '管理员',
];
foreach ($qc_group as $key => $value){
$conn->query("INSERT INTO `qc_group` (`gid`, `name`)
VALUES ('". $key ."', '". $value ."');");
}
//qc_user 用户数据基本表
$conn->query("CREATE TABLE `qc_user` (
`uid` INT NOT NULL AUTO_INCREMENT COMMENT '用户Id',
`username` TEXT NOT NULL COMMENT '用户名',
`password` TEXT NOT NULL COMMENT '用户密码',
`reg_date` INT NOT NULL COMMENT '注册时间(时间戳)',
`email` TEXT NOT NULL COMMENT '邮箱',
`phone` TEXT NOT NULL COMMENT '手机号',
`gender` tinyint NOT NULL DEFAULT '0' COMMENT '性别(0:未知,1:男,2:女)',
`gid` tinyint(4) NOT NULL DEFAULT '1' COMMENT '用户所在组',
FOREIGN KEY (`gid`) REFERENCES `qc_group` (`gid`),
PRIMARY KEY (`uid`)
) ENGINE = InnoDB;");
//qc_avatar 用户头像表
$conn->query("CREATE TABLE `qc_avatar` (
`uid` int(11) NOT NULL COMMENT '用户uid',
`avatar_url` text NOT NULL COMMENT '头像Url',
FOREIGN KEY (`uid`) REFERENCES `qc_user` (`uid`)
);");
$conn->query("ALTER TABLE `qc_avatar`
ADD FOREIGN KEY (`uid`) REFERENCES `qc_user` (`uid`);");
//qc_phone_sms 短信验证记录表
$conn->query("CREATE TABLE `qc_phone_sms` (
`lid` INT NOT NULL AUTO_INCREMENT COMMENT 'ID',
`target` TEXT NOT NULL COMMENT '目标手机号',
`sendTime` INT NOT NULL COMMENT '发送时间(时间戳)',
`sendIP` TEXT NOT NULL COMMENT '发送者IP',
`code` INT NOT NULL COMMENT '短信代码',
`flag` tinyint NOT NULL DEFAULT '0' COMMENT '使用标记',
PRIMARY KEY (`lid`)
) ENGINE = InnoDB;");
//qc_user_detail 用户详情信息表
$conn->query("CREATE TABLE `qc_user_detail` (
`uid` int(11) NOT NULL COMMENT '唯一指定Uid',
`realname` tinytext NOT NULL COMMENT '用户真实姓名',
`education` tinyint NOT NULL COMMENT '学历(1:小学,2:初中,3:高中,4:大学,5:其他)',
`grade` tinyint NOT NULL COMMENT '年级',
FOREIGN KEY (`uid`) REFERENCES `qc_user` (`uid`)
);");
//qc_log 日志表
$conn->query("CREATE TABLE `qc_log` (
`lgid` int NOT NULL COMMENT '日志Id' AUTO_INCREMENT PRIMARY KEY,
`type` tinytext NOT NULL COMMENT '日志类型',
`detail` text NOT NULL COMMENT '日志内容',
`ip` text NOT NULL COMMENT '操作IP',
`uid` int NOT NULL COMMENT '操作uid',
`env` text NOT NULL COMMENT '操作环境',
`result` tinyint NOT NULL COMMENT '操作结果(小于0失败,大于0成功)',
`time` int NOT NULL COMMENT '操作时间(时间戳)'
);");
//qc_visit_log 日志表
$conn->query("CREATE TABLE `qc_visit_log` (
`vlid` int NOT NULL COMMENT '日志主键' AUTO_INCREMENT PRIMARY KEY,
`method` tinytext NOT NULL COMMENT '请求方法',
`ip` tinytext NOT NULL COMMENT '请求IP',
`uid` int NOT NULL COMMENT '操作用户',
`server` text NOT NULL COMMENT '\$_SERVER',
`time` int NOT NULL COMMENT '时间',
`url` text NOT NULL COMMENT '请求地址'
);");
//qc_course 课程 表
$conn->query("CREATE TABLE `qc_course` (
`scid` int NOT NULL COMMENT '课程ID' AUTO_INCREMENT PRIMARY KEY,
`name` text NOT NULL COMMENT '课程标题',
`describe` text NOT NULL COMMENT '课程介绍',
`type` tinyint NOT NULL COMMENT '类型,1:直播课,2:录播课',
`subject` tinytext NOT NULL COMMENT '学科',
`teacher` int(11) NOT NULL COMMENT '上课老师',
`stream_id` tinytext NOT NULL COMMENT '直播流ID',
`start_time` int NOT NULL COMMENT '开课时间',
`over_time` int NOT NULL COMMENT '结束时间',
`file_url` text NOT NULL COMMENT '录播文件URL',
`subtitle_url` tinytext NOT NULL COMMENT '字幕地址',
FOREIGN KEY (`teacher`) REFERENCES `qc_user` (`uid`)
);");
//qc_course_list 课程列表 表
$conn->query("CREATE TABLE `qc_course_list` (
`lid` int NOT NULL COMMENT '课程列表ID' AUTO_INCREMENT PRIMARY KEY,
`creater` int NOT NULL COMMENT '创建者UID',
`created_time` int NOT NULL COMMENT '创建时间',
`subject` int NOT NULL COMMENT '科目',
`list` text NOT NULL COMMENT '课程列表(JSON)',
`cost` int NOT NULL DEFAULT '0' COMMENT '价格'
);");
$conn->close();
echo "青草课堂 :构建测试成功! \n";
?>