对于datetime类型还是timestamp类型都是用格式化的时间戳存储,为什么老师可以直接用time()出来的时间戳存储???
CREATE TABLE IF NOT EXISTS `restful`.`article` ( `articleId` INT UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '文章ID', `title` VARCHAR(40) NOT NULL COMMENT '标题', `createdAt` INT NOT NULL COMMENT '发表时间', `content` TEXT NOT NULL COMMENT '文章内容', `userId` INT NOT NULL COMMENT '用户ID', PRIMARY KEY (`articleId`), INDEX `title` (`title` ASC), INDEX `createdAt` (`createdAt` ASC), INDEX `fk_article_user_idx` (`userId` ASC), CONSTRAINT `fk_article_user` FOREIGN KEY (`userId`) REFERENCES `restful`.`user` (`userId`) ON DELETE NO ACTION ON UPDATE NO ACTION) ENGINE = InnoDB;
数据库createdAt字段是int类型,可以存时间戳
date_default_timezone_set('PRC');
$add_time = date("Y-m-d H:i:s");
datetime类型和timestamp类型都可以存储int,只是会被mysql自动转换为0000-00-00 00:00:00