PHP电商购物车(一:建立数据表)

来源:互联网 发布:四维星瓷砖设计软件 编辑:程序博客网 时间:2024/04/29 13:33

                      PHP电商购物车功能———建立数据表


      最近几天,简单完成了OOP学习阶段的购物车功能环节,将以前的一些知识都简单的运用了,总的来说,总结一下这个功能版块还是很有必要的。

      购物车以当当网为范例,商品就以图书为例。

      第一步:设计数据表。

         模型图:

                                   

    2.建表与表关系:

/*==============================================================*/
/* DBMS name:      MySQL 5.0                                    */
/* Created on:     2016/7/4 20:54:17                            */
/*==============================================================*/


drop table if exists bookshop;

drop table if exists booktype;

drop table if exists myuser;

drop table if exists shopcar;

/*==============================================================*/
/* Table: bookshop 上图图书表                                             */
/*==============================================================*/
create table bookshop
(
   b_id                 int not null auto_increment comment '图书ID',
   b_name               varchar(100) not null comment '图书名',
   b_cover              varchar(100) not null comment '封面图片(存储图片的文件路径)',
   b_introduction       varchar(1200) not null comment '图书简介',
   b_author             varchar(30) not null comment '作者',
   b_press              varchar(100) not null comment '出版社',
   b_type               int,
   b_pressTime          date not null comment '出版时间',
   b_price              decimal(10,2) not null comment '价格',
   b_save               int not null comment '库存',
   primary key (b_id)
);

/*==============================================================*/
/* Table: booktype       上图书籍类型表                                       */
/*==============================================================*/
create table booktype
(
   b_typeid             int not null comment '类别ID',
   b_type               varchar(50) not null comment '类别',
   primary key (b_typeid)
);

/*==============================================================*/
/* Table: myuser          上图用户表                                      */
/*==============================================================*/
create table myuser
(
   u_id                 int not null auto_increment comment '用户ID',
   u_name               varchar(30) not null comment '用户名',
   u_password           varchar(20) not null comment '用户登录密码',
   u_createtime         datetime not null comment '用户注册时间',
   u_isvalid            tinyint not null comment '该用户身份是否有效',
   primary key (u_id)
);

alter table myuser comment '用户表';

/*==============================================================*/
/* Table: shopcar          上图购物车                                     */
/*==============================================================*/
create table shopcar
(
   u_id                 int not null comment '用户ID',
   b_id                 int not null comment '图书ID',
   s_num                int not null comment '购买数量',
   s_time               datetime not null comment '采购时间',
   primary key (u_id, b_id)
);
  #外键关系
alter table booktype add constraint FK_b_type foreign key (b_typeid)
      references bookshop (b_id) on delete restrict on update restrict;

alter table shopcar add constraint FK_b_id foreign key (b_id)
      references bookshop (b_id) on delete restrict on update restrict;

alter table shopcar add constraint FK_u_id foreign key (u_id)
      references myuser (u_id) on delete restrict on update restrict;


  3. 说明。

   在这个数据库中,只是为了简单实现购物车的功能,实际的购物车的数据库还会复杂的多,比如在每个表中都应该有状态列,时数据不直接删除,密码列的加密,至少还应有一张购买表记录购买信息,一张商品收藏表等等,还有很多细节就不一 一实现了,重点主要在使用PHP实现购物车方面。

0 0