[TOC]
## 数据库设计
~~~
DROP DATABASE IF EXISTS lost;
CREATE DATABASE lost;
use lost;
DROP TABLE IF EXISTS `think_event`;
CREATE TABLE `think_event`
(
`id` int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,
`user_id` int(11) COMMENT '用户ID',
`type` varchar(10) NOT NULL COMMENT '事件类型:lost|found',
`title` varchar(50) NOT NULL COMMENT '事件标题',
`linkman` varchar(50) NOT NULL COMMENT '联系人',
`mobile` varchar(50) NOT NULL COMMENT '联系电话',
`create_time` int(11) COMMENT '事件发生时间',
`image_ids` varchar(500) COMMENT '关联的图片ID串',
`tags` varchar(500) COMMENT 'tags',
`address` varchar(500) COMMENT '事件发生的地点',
`description` TEXT COMMENT '简要描述',
`status` int(11) COMMENT '状态',
`delete_time` int(11) DEFAULT 0 COMMENT '删除时间'
) ENGINE = InnoDB
DEFAULT CHARSET = utf8 COMMENT ='失物招领事件表';
DROP TABLE IF EXISTS `think_image`;
CREATE TABLE IF NOT EXISTS `think_image`
(
`id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT '主键id自增',
`storage` varchar(50) NOT NULL,
`path` varchar(255) NOT NULL DEFAULT '' COMMENT '路径',
`base_url` varchar(255) NOT NULL DEFAULT '' COMMENT '图片链接',
`md5` char(32) NOT NULL DEFAULT '' COMMENT '文件md5',
`create_time` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '创建时间',
PRIMARY KEY (`id`)
) ENGINE = MyISAM
DEFAULT CHARSET = utf8
AUTO_INCREMENT = 1;
--
-- 表的结构 `think_user`
--
/*用户基础信息,记录登陆账号信息*/
DROP TABLE IF EXISTS `think_user`;
CREATE TABLE `think_user`
(
`id` int(10) AUTO_INCREMENT PRIMARY KEY NOT NULL,
`username` varchar(50) NOT NULL,
`user_type` varchar(50) NOT NULL DEFAULT 'user', #注册用户的类型,user,school,student,teacher,company
`mobile` varchar(11) DEFAULT NULL,
`email` varchar(100) DEFAULT NULL,
`password` varchar(32) NOT NULL,
`encrypt` varchar(10) NOT NULL,
`avator_id` int DEFAULT 0 COMMENT '头像在image库中的ID',
`last_login_time` int DEFAULT 0,
`last_login_ip` varchar(50) DEFAULT '',
`login_count` int(10) unsigned NOT NULL DEFAULT 0 COMMENT '登录次数',
`login_fail_count` int(10) unsigned NOT NULL DEFAULT 0 COMMENT '登录失败次数',
`deletable` tinyint(2) NOT NULL DEFAULT 0 COMMENT '可删除,默认不可删除',
`status` tinyint(2) NOT NULL DEFAULT 1 COMMENT '状态,默认激活',
`delete_time` int NOT NULL DEFAULT 0,
`create_time` int NOT NULL DEFAULT 0,
`create_ip` varchar(50) NOT NULL DEFAULT ''
) ENGINE = InnoDB
DEFAULT CHARSET = utf8mb4;
--
-- 转存表中的数据 `think_user`
-- password:123456
--
INSERT INTO `think_user` (`id`, `username`, `password`, `encrypt`)
VALUES (1, 'admin', 'ce9ac4724c59b5167ae89ecc345a57c9', 'Cc6bSCcc3N'),
(2, 'guest', 'ce9ac4724c59b5167ae89ecc345a57c9', 'Cc6bSCcc3N'),
(3, 'user', 'ce9ac4724c59b5167ae89ecc345a57c9', 'Cc6bSCcc3N');
~~~
## 配置数据库连接
修改项目更目录下的.env文件,设置DATABASE节的内容,设置正确的数据库名和账号、密码信息。
> 添加一行,设置表的前缀:think_
~~~
PREFIX = think_
~~~
> 完整的.env文件如下:
```
APP_DEBUG = true
[APP]
DEFAULT_TIMEZONE = Asia/Shanghai
[DATABASE]
TYPE = mysql
HOSTNAME = 127.0.0.1
DATABASE = lost
PREFIX = think_
USERNAME = root
PASSWORD = root
HOSTPORT = 3306
CHARSET = utf8
DEBUG = true
[LANG]
default_lang = zh-cn
```