当前位置:文档之家› 教你如何连接数据库

教你如何连接数据库

create database csy;
show databases;
进 入
use csy;
use xxxxx;
show tables;
删除
drop database csy;
create database if not exists xxxxx;数据库名称
drop database 数据库名称
drop database if exists qq;

drop database if exists myschool;


创建表格和删除数据库
create database if not exists csy;
use csy;
create table if not exists users(
userCode int(5),
userName int(5),
password int(5),
email int(5),
tel double
);

drop table if exists user;
desc myschool;(查表)
insert into user(username,userpwd) values('153********','123');

create table if not exists question(
userId int primary key auto_increment ,
answer varchar(20),
title varchar(20),
optionA varchar(20),
optionB varchar(20),
optionC varchar(20),
optionD varchar(20)
);

insert into question(answer,title,optionA,optionB,optionC,optionD) values(1,1,1,1,1,1);







select username from user;
select * from user;

修改和删除
陈松阳密码修改为123456789
修改 update user set userpwd='123456789' where username='153********';
删除 delete from user where username='153********';
#primary key是主键
create database if not exists myschool;
use myschool;
create table if not exists user(
id int(6) not null primary key,
name nvarchar(5),
age int(3),
fenshu double
);
insert into user(userCode,userName,password,email,tel) values(1,1,1,1,1.0);
insert into user(id,name,age,fenshu) values(2,'葩葩哥',17,50);
insert into user(id,name,age,fenshu) values(3,'小明',16,61);
insert into user(id,name,age,fenshu) values(4,'陈小红',15,52);
insert into user(id,name,age,fenshu) values(5,'papi酱',17,80);


select * from user where id=1;
select name from user where fenshu<60;

select * from user where name like %陈%;
select * from user where name like 小%;

delete from user where id=1;
update user set fenshu=100 wher id=2;


C:\Program Files\MySQL\MySQL Server 5.5\bin\mysqld" --defaults-file="C:\Program Files\MySQL\MySQL Server 5.5\my.ini" MySQL

desc myschool;



第一步 根据大纲找对象
1:咋们需要里头有几个对象
1:游戏商店
2:顾客
3:植物

第二步:根据对象设计数据库表

第一张表:游戏商店表
字段:植物id 植物名称 植物价格

第二张表:顾客表
字段:登录账号 登录密码 钱

第三张表:购买了植物表
字段:植物id 购买者id 雨露值 阳光值 健康值 价格




create table if not exists plant(
Z_id int(6) not null primary key,
Z_user_id varchar(11),
Z_rainnumber int(5),
Z_sunnumber int(5),
Z_heanumber int(5),
Z_money double


);
create table if not exists plant(
u_id int(6) not null primary key,
u_user_id varchar(11),
u_rainnumber int(5),
u_sunnu

mber int(5),
u_heanumber int(5),
u_money double


);
create table if not exists plant(
Zu_id int(6) not null primary key,
Zu_user_id varchar(11),
Zu_rainnumber int(5),
Zu_sunnumber int(5),
Zu_heanumber int(5),
Zu_money double


);
Use game;
drop table if exists shop;
create table if not exists shop(
Z_id int(6) not null primary key auto_increment,
Z_name varchar(20),
Z_money double


);


user对象接口
1:注册(UserRes)
需要传值u_id(手机号) u_pwd(登录密码) u_money(默认注册金币)
2:登录(UserLogin)
需要传值u_id(手机号) u_pwd(登录密码)
需要返回值:UserEntity 登录成功
3:修改网名(UserUpdateName)
需要传值u_id(手机号) u_name(新的网名)
需要返回值:int=1 修改成功
4:修改密码(UserUpdatPwd)
需要传值u_id(手机号) u_pwd(新的密码)
需要返回值:int=1 修改成功
5:减少金币(UserUpdatemoney)
需要传值u_id(手机号) u_money(需要减少的钱)
需要返回值:int=1 修改成功
5:增加金币(UserUpdatemoney)
需要传值u_id(手机号) u_money(需要增加的钱)
需要返回值:int=1 修改成功



plant对象接口
1:减少金币(UserUpdatemoney)
需要传值Zu_id(增加植物的id) Zu_user_id(增加植物的id) u_money(植物购买的金币)
需要返回值:int=1 注册成功

2:修改雨露值(PlantUpdatRain)
需要传值Zu_id(植物id)
需要返回值:int=1 修改成功

3:修改阳光值(PlantUpdatRun)
需要传值Zu_id(植物id)
需要返回值:int=1 修改成功
4:修改健康值(PlantUpdatHea)
需要传值Zu_id(植物id)
需要返回值:int=1 修改成功
4:删除一个植物

需要传值Zu_id(植物id)
需要返回值:int=1 修改成功



4:查找植物的所有列表(PlantList)

需要传值Zu_user_id(购买者id)
需要返回值:list 查询成功

4:根据植物id,查询单个植物(PlantList)

需要传值Zu_id(植物id)
需要返回值:PlantEntity 查询成功







shop对象接口
1:查找商店的所有植物列表(PlantList)

需要传值Zu_user_id(购买者id)
需要返回值:list 查询成功

2:根据植物id,查询单个植物(PlantList)

需要传值Z_id(植物id)
需要返回值:ShopEntity 查询成功






















































































相关主题
文本预览
相关文档 最新文档