posted on 2023-06-06 10:54 read(1039) comment(0) like(27) collect(4)
sql file download link: https://download.csdn.net/download/m0_63975371/87094012
Python file download link: https://download.csdn.net/download/m0_63975371/87093891
By understanding the characteristics and actual situation of the catering industry, starting from the analysis of the basic situation of the hotel, combined with the functions to be realized, the feasibility of the system is analyzed. In order to improve its feasibility, the following data analysis is done to complete the restaurant point meal system
2.1 Data Requirements
Table data includes table number, number of seats, status (empty/occupied). The restaurant stores customer information and employee information. The dish information includes dish number, name, category, price and so on.
The specific data requirements are as follows:
2.1.1 Data required at the stage of placing an order:
Customer information: including customer number.
Order information: including order number and consumption time.
Table information: including number, capacity, usage status, etc.
Employee information: including employee ID.
2.1.2 Data required in the order stage:
Order information: order number
Dishes information: including dish number, dish name, dish quantity, etc.
2.1.3 Data required in the checkout stage:
Order information: including order number, customer number
Dishes information: including dish number, dish name, dish quantity, etc.
Employee information: including employee ID
Discount information: including consumption amount and discount number
2.1.4 Data required for employee management:
Employee files: including job number, name, gender, salary
2.1.5 Data required for customer management:
Customer profile: including number, name, gender, etc.
2.1.6 The data required for consumption record management are:
Consumption information: order number, consumption amount, discount amount, checkout time
2.2 Business requirements
2.2.1 Data Entry
Enter customer information, enter table information, enter employee information, enter dish information
2.2.2 Data update/deletion
Update/delete table information, update/delete recipe information, update/delete employee information, update/delete customer information, update/delete order dish information
2.2.3 Data query
Query available table information, query information about dishes on sale, query order information, query customer order information, query employee information, query customer consumption information
3.1 Menu (Menus) ER diagram
3.2 Customer (Tomer) ER Diagram
3.3 Table (FoodTable) ER diagram
3.4 Employee (Worke) ER Diagram
3.5 Order (Oder) ER Diagram
3.6 Consumption record (Sales_bill) ER diagram
3.7 Discount rules (Discount_rules) ER diagram
3.8 Global ER Diagram
4.1 Conversion rules
An entity type is transformed into a relational model. The attribute of the entity is the attribute of the relationship, and the code of the entity is the code of the relationship.
The relationship between entity types often has the following different situations:
a. A 1:1 relationship can be converted into an independent relational schema, or merged with the corresponding relational schemas at either end.
b. A 1:n relationship can be converted into an independent relational schema, or merged with the corresponding relational schema at the n end.
c. An m:n relationship is transformed into a relational schema.
d. A multi-link between 3 or more entities can be converted into a relational schema.
e. Relational schemas with the same key can be merged.
4.1.1 Relational model: (red is the main code)
Recipe ( dish number , dish name, dish category, dish price)
Customer ( customer number , name, gender, age, contact information)
Table ( table number , number of seats, usage status)
Employee ( employee number , name, gender, age, salary)
Order ( order number , customer number, consumption time, table number, waiter number)
Recipe_order ( order number, dish number , dish name, dish quantity)
Consumption records ( order number , consumption amount, discounted amount, billing time)
Discount rules ( consumption amount , discount)
4.2 Create a basic table
4.2.1 Menus (Menus)
create table Menus(
M_id varchar(10) primary key,
M_name varchar(20),
M_class varchar(10),
M_price float);
4.2.2 Customer (Tomer)
create tale Tomer
(T_id varchar(10) primary key,
T_name varchar(10) not null
T_rsex varchar(4) check (T_sex='male' or T_sex='female') ,
T_phone varchar(20) );
4.2.3 Table (FoodTable)
create table Foodtable
(Cz_id varchar(10) primary key,
Cz_number int not null,
Cz_zt varchar(6)check(Cz_zt="empty" or Cz_zt="someone"));
4.2.4 Workers
create table Worke
(W_id varchar(10) primary key, W_name varchar(10),
W_sex varchar(4) check(W_sex='男' or W_sex='女'),
W_age int,
W_salary float) ;
4.2.5 Order (Oder)
create table Menus_Or
(O_id varchar(10),
M_id varchar(10),
M_name varchar(10),
M_number int not null,
Primary key(M_id ,O_id),
foreign key(M_id) references Menus(M_id ),
foreign key(O_id) references Oder(O_id) ) ;
4.2.6 Menu_Order (Menus_Oder)
create table Menus_Or
(O_id varchar(10),
M_id varchar(10),
M_name varchar(10),
M_number int not null,
Primary key(M_id ,O_id),
foreign key(M_id) references Menus(M_id ),
foreign key(O_id) references Oder(O_id) ) ;
4.2.7 Discount Rules (Discount_rules)
create table Discount_rules
(Is a float primary key,
Zk float);
4.2.8 Consumption bill (Sales_bill)
create table Sales_bill
(O_id varchar(10) primary key ,
S_price float,
S_priceafter float,
time datetime,
foreign key(O_id ) references Oder(O_id ) );
4.3 Manage basic tables
有时候应用环境和应用需求的改变,我们需要修改已经建立好的基本表的模式结构或者更新已经插入的数据。mysql语句采用alter table<>语句修改基本表的结构,利用drop<>子句删除基本表,利用update更新已经插入的数据。alter table语句以修改基本表的名字,增加新列或者增加新的完整性约束条件,修改原有列的定义,包括修改列名和数据类型等。drop子句用于删除指定的完整性约束条件。UPDATE用于把插入表的数据更新改变。
因为在建立表时将Tomer表中的T_sex错误的录为T_rsex,因此用alter table 表名 change 旧字段名 新字段名 新字段类型。
访问数据库
5.1数据查询
5.1.1 Foodtable表
5.2.1menus表
5.1.3员工表(worke)
5.1.4消费记录( Sales_bill)
5.1.5顾客(Tomer)
5.1.6订单(Oder)
5.1.7折扣规则(Discount_rules)
5.1.8点菜(menus_oder)
5.2数据更新
将员工表(worker)中的01号员工W_age数据项改为20.
原来的表:
改过之后
5.3python连接数据库
对数据库进行测试:
基础点餐系统:
5.4数据库的维护
数据库维护包括许多内容,包括用户权限的设置、数据库完整性维护、数据库的备份、表的备份、日志备份等。
5.4.1备份数据库
完全备份:这是大多数人常用的方式,它可以备份整个数据库,包含用户表、系统表、索引、视图和存储过程等所有数据库对象。但它需要花费更多的时间和空间,所以,一般推荐一周做一次完全备份。
事务日志备份:事务日志是一个单独的文件,它记录数据库的改变,备份的时候只需要复制自上次备份以来对数据库所做的改变,所以只需要很少的时间。为了使数据库具有鲁棒性,推荐每小时甚至更频繁的备份事务日志。
差异备份:也叫增量备份。它是只备份数据库一部分的另一种方法,它不使用事务日志,相反,它使用整个数据库的一种新映象。它比最初的完全备份小,因为它只包含自上次完全备份以来所改变的数据库。它的优点是存储和恢复速度快。推荐每天做一次差异备份。
文件备份:数据库可以由硬盘上的许多文件构成。如果这个数据库非常大,并且一个晚上也不能将它备份完,那么可以使用文件备份每晚备份数据库的一部分。由于一般情况下数据库不会大到必须使用多个文件存储,所以这种备份不是很常用。
1.sql代码
-- ----------------------------
-- Records of discount_rules
-- ----------------------------
INSERT INTO `discount_rules` VALUES ('100', '9.9');
INSERT INTO `discount_rules` VALUES ('200', '9.5');
INSERT INTO `discount_rules` VALUES ('300', '9.2');
INSERT INTO `discount_rules` VALUES ('500', '9');
INSERT INTO `discount_rules` VALUES ('1000', '8.5');
-- ----------------------------
-- Table structure for foodtable
-- ----------------------------
DROP TABLE IF EXISTS `foodtable`;
CREATE TABLE `foodtable` (
`Cz_id` varchar(10) NOT NULL,
`Cz_number` int(11) NOT NULL,
`Cz_zt` varchar(6) DEFAULT NULL,
PRIMARY KEY (`Cz_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
-- ----------------------------
-- Records of foodtable
-- ----------------------------
INSERT INTO `foodtable` VALUES ('1', '6', '有人');
INSERT INTO `foodtable` VALUES ('2', '6', '空');
INSERT INTO `foodtable` VALUES ('3', '6', '空');
INSERT INTO `foodtable` VALUES ('4', '6', '空');
INSERT INTO `foodtable` VALUES ('5', '8', '空');
INSERT INTO `foodtable` VALUES ('6', '8', '有人');
INSERT INTO `foodtable` VALUES ('7', '8', '有人');
INSERT INTO `foodtable` VALUES ('8', '8', '空');
INSERT INTO `foodtable` VALUES ('9', '10', '有人');
-- ----------------------------
-- Table structure for menus
-- ----------------------------
DROP TABLE IF EXISTS `menus`;
CREATE TABLE `menus` (
`M_id` varchar(10) NOT NULL,
`M_name` varchar(20) DEFAULT NULL,
`M_class` varchar(10) DEFAULT NULL,
`M_price` float DEFAULT NULL,
PRIMARY KEY (`M_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
-- ----------------------------
-- Records of menus
-- ----------------------------
INSERT INTO `menus` VALUES ('001', '小鸡炖蘑菇', '荤素搭配', '49.99');
INSERT INTO `menus` VALUES ('002', '黄焖鸡', '荤', '12');
INSERT INTO `menus` VALUES ('003', '混沌', '荤', '10');
INSERT INTO `menus` VALUES ('004', '混沌', '素', '8');
INSERT INTO `menus` VALUES ('005', '兰州拉面', '素', '10');
INSERT INTO `menus` VALUES ('006', '鸭血粉丝', '荤素搭配', '9.99');
INSERT INTO `menus` VALUES ('007', '小酥肉', '荤', '11.99');
INSERT INTO `menus` VALUES ('008', '大盘鸡', '荤', '55.99');
INSERT INTO `menus` VALUES ('009', '烤鱼', '荤', '20.99');
INSERT INTO `menus` VALUES ('010', '花生米', '小吃', '5.99');
INSERT INTO `menus` VALUES ('011', '啤酒', '饮品', '4.5');
INSERT INTO `menus` VALUES ('012', '腐竹', '素', '10');
INSERT INTO `menus` VALUES ('013', '拍黄瓜', '素', '5.5');
-- ----------------------------
-- Table structure for menus_oder
-- ----------------------------
DROP TABLE IF EXISTS `menus_oder`;
CREATE TABLE `menus_oder` (
`O_id` varchar(10) NOT NULL,
`M_id` varchar(10) NOT NULL,
`M_name` varchar(10) DEFAULT NULL,
`M_number` int(11) NOT NULL,
PRIMARY KEY (`M_id`,`O_id`),
KEY `O_id` (`O_id`),
CONSTRAINT `menus_oder_ibfk_1` FOREIGN KEY (`M_id`) REFERENCES `menus` (`M_id`),
CONSTRAINT `menus_oder_ibfk_2` FOREIGN KEY (`O_id`) REFERENCES `oder` (`O_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
-- ----------------------------
-- Records of menus_oder
-- ----------------------------
INSERT INTO `menus_oder` VALUES ('000001', '001', '小鸡炖蘑菇', '20');
INSERT INTO `menus_oder` VALUES ('000020', '001', '兰州拉面', '23');
INSERT INTO `menus_oder` VALUES ('000002', '002', '黄焖鸡', '24');
INSERT INTO `menus_oder` VALUES ('000003', '003', '混沌', '25');
INSERT INTO `menus_oder` VALUES ('000007', '003', '混沌', '40');
INSERT INTO `menus_oder` VALUES ('000013', '003', '小鸡炖蘑菇', '25');
INSERT INTO `menus_oder` VALUES ('000015', '003', '腐竹', '38');
INSERT INTO `menus_oder` VALUES ('000018', '003', '鸭血粉丝', '50');
INSERT INTO `menus_oder` VALUES ('000004', '004', '混沌', '23');
INSERT INTO `menus_oder` VALUES ('000014', '004', '兰州拉面', '23');
INSERT INTO `menus_oder` VALUES ('000005', '005', '兰州拉面', '28');
INSERT INTO `menus_oder` VALUES ('000008', '005', '烤鱼', '50');
INSERT INTO `menus_oder` VALUES ('000016', '005', '兰州拉面', '40');
INSERT INTO `menus_oder` VALUES ('000005', '006', '鸭血粉丝', '38');
INSERT INTO `menus_oder` VALUES ('000010', '006', '兰州拉面', '23');
INSERT INTO `menus_oder` VALUES ('000014', '006', '花生米', '28');
INSERT INTO `menus_oder` VALUES ('000017', '006', '混沌', '40');
INSERT INTO `menus_oder` VALUES ('000006', '007', '小酥肉', '40');
INSERT INTO `menus_oder` VALUES ('000009', '008', '烤鱼', '46');
INSERT INTO `menus_oder` VALUES ('000012', '008', '黄焖鸡', '24');
INSERT INTO `menus_oder` VALUES ('000019', '008', '拌黄瓜', '46');
INSERT INTO `menus_oder` VALUES ('000011', '009', '鸭血粉丝', '20');
-- ----------------------------
-- Table structure for oder
-- ----------------------------
DROP TABLE IF EXISTS `oder`;
CREATE TABLE `oder` (
`O_id` varchar(10) NOT NULL,
`T_id` varchar(10) NOT NULL,
`time` datetime NOT NULL,
`Cz_id` varchar(10) NOT NULL,
`W_id` varchar(10) NOT NULL,
PRIMARY KEY (`O_id`),
KEY `T_id` (`T_id`),
KEY `Cz_id` (`Cz_id`),
KEY `W_id` (`W_id`),
CONSTRAINT `oder_ibfk_1` FOREIGN KEY (`T_id`) REFERENCES `tomer` (`T_id`),
CONSTRAINT `oder_ibfk_2` FOREIGN KEY (`Cz_id`) REFERENCES `foodtable` (`Cz_id`),
CONSTRAINT `oder_ibfk_3` FOREIGN KEY (`W_id`) REFERENCES `worke` (`W_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
-- ----------------------------
-- Records of oder
-- ----------------------------
INSERT INTO `oder` VALUES ('000001', '00001', '2020-06-01 09:30:45', '1', '01');
INSERT INTO `oder` VALUES ('000002', '00002', '2021-06-22 16:15:31', '2', '02');
INSERT INTO `oder` VALUES ('000003', '00003', '2021-06-22 16:15:57', '3', '03');
INSERT INTO `oder` VALUES ('000004', '00004', '2021-06-22 16:16:19', '4', '04');
INSERT INTO `oder` VALUES ('000005', '00005', '2021-06-22 16:16:40', '5', '05');
INSERT INTO `oder` VALUES ('000006', '00006', '2021-06-22 16:17:01', '6', '06');
INSERT INTO `oder` VALUES ('000007', '00007', '2021-06-22 16:17:23', '7', '07');
INSERT INTO `oder` VALUES ('000008', '00008', '2021-06-22 16:17:47', '8', '08');
INSERT INTO `oder` VALUES ('000009', '00009', '2021-06-22 16:18:07', '9', '09');
INSERT INTO `oder` VALUES ('000010', '00010', '2021-06-22 16:18:30', '1', '10');
INSERT INTO `oder` VALUES ('000011', '00011', '2021-06-22 16:19:08', '2', '01');
INSERT INTO `oder` VALUES ('000012', '00012 ', '2021-06-22 16:19:28', '3', '02');
INSERT INTO `oder` VALUES ('000013', '00013', '2021-06-22 16:19:53', '4', '03');
INSERT INTO `oder` VALUES ('000014', '00014', '2021-06-22 16:20:17', '5', '04');
INSERT INTO `oder` VALUES ('000015', '00015', '2021-06-22 16:20:40', '6', '05');
INSERT INTO `oder` VALUES ('000016', '00016', '2021-06-22 16:21:08', '7', '06');
INSERT INTO `oder` VALUES ('000017', '00017', '2021-06-22 16:21:33', '8', '07');
INSERT INTO `oder` VALUES ('000018', '00018', '2021-06-22 16:21:54', '9', '08');
INSERT INTO `oder` VALUES ('000019', '00019', '2021-06-22 16:22:12', '1', '09');
INSERT INTO `oder` VALUES ('000020', '00020', '2021-06-22 16:22:34', '2', '10');
-- ----------------------------
-- Table structure for sales_bill
-- ----------------------------
DROP TABLE IF EXISTS `sales_bill`;
CREATE TABLE `sales_bill` (
`O_id` varchar(10) NOT NULL,
`S_price` float DEFAULT NULL,
`S_priceafter` float DEFAULT NULL,
`time` datetime DEFAULT NULL,
PRIMARY KEY (`O_id`),
CONSTRAINT `sales_bill_ibfk_1` FOREIGN KEY (`O_id`) REFERENCES `oder` (`O_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
-- ----------------------------
-- Records of sales_bill
-- ----------------------------
INSERT INTO `sales_bill` VALUES ('000001', '100.07', '99.0693', '2021-06-22 16:42:22');
INSERT INTO `sales_bill` VALUES ('000002', '120.25', '119.048', '2021-06-22 16:42:24');
INSERT INTO `sales_bill` VALUES ('000003', '132.52', '131.195', '2021-06-22 16:42:28');
INSERT INTO `sales_bill` VALUES ('000004', '154.42', '152.876', '2021-06-22 16:42:31');
INSERT INTO `sales_bill` VALUES ('000005', '2546.2', '2164.27', '2021-06-22 16:42:35');
INSERT INTO `sales_bill` VALUES ('000006', '487.45', '448.454', '2021-06-22 16:42:38');
INSERT INTO `sales_bill` VALUES ('000007', '165.23', '163.578', '2021-06-22 16:42:41');
INSERT INTO `sales_bill` VALUES ('000008', '235.55', '223.773', '2021-06-22 16:42:44');
INSERT INTO `sales_bill` VALUES ('000009', '345.26', '317.639', '2021-06-22 16:42:47');
INSERT INTO `sales_bill` VALUES ('000010', '256.42', '243.599', '2021-06-22 16:42:50');
INSERT INTO `sales_bill` VALUES ('000011', '354.42', '326.006', '2021-06-22 16:42:52');
INSERT INTO `sales_bill` VALUES ('000012', '145.23', '143.778', '2021-06-22 16:42:54');
INSERT INTO `sales_bill` VALUES ('000013', '200.12', '190.114', '2021-06-22 16:42:57');
INSERT INTO `sales_bill` VALUES ('000014', '300.14', '276.129', '2021-06-22 16:42:59');
INSERT INTO `sales_bill` VALUES ('000015', '1000.23', '850.195', '2021-06-22 16:43:01');
INSERT INTO `sales_bill` VALUES ('000016', '154.15', '152.609', '2021-06-22 16:43:03');
INSERT INTO `sales_bill` VALUES ('000017', '1120.23', '952.192', '2021-06-22 16:43:05');
INSERT INTO `sales_bill` VALUES ('000018', '1523.45', '1294.93', '2021-06-22 16:43:08');
INSERT INTO `sales_bill` VALUES ('000019', '123.23', '121.998', '2021-06-22 16:43:11');
INSERT INTO `sales_bill` VALUES ('000020', '154.5', '326.14', '2021-06-22 16:43:14');
-- ----------------------------
-- Table structure for tomer
-- ----------------------------
DROP TABLE IF EXISTS `tomer`;
CREATE TABLE `tomer` (
`T_id` varchar(10) NOT NULL,
`T_name` varchar(10) NOT NULL,
`T_rsex` varchar(4) DEFAULT NULL,
`T_phone` varchar(20) DEFAULT NULL,
PRIMARY KEY (`T_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
-- ----------------------------
-- Records of tomer
-- ----------------------------
INSERT INTO `tomer` VALUES ('00001', '李一', '男', '12345678910');
INSERT INTO `tomer` VALUES ('00002', '李二', '男', '11345678910');
INSERT INTO `tomer` VALUES ('00003', '李三', '男', '12145678910');
INSERT INTO `tomer` VALUES ('00004', '李四', '男', '12315678910');
INSERT INTO `tomer` VALUES ('00005', '李五', '男', '12341678910');
INSERT INTO `tomer` VALUES ('00006', '李六', '男', '12345178910');
INSERT INTO `tomer` VALUES ('00007', '李七', '女', '15936053010');
INSERT INTO `tomer` VALUES ('00008', '李八', '女', '12345671910');
INSERT INTO `tomer` VALUES ('00009', '李九', '女', '12345678110');
INSERT INTO `tomer` VALUES ('00010', '李十', '男', '12345678900');
INSERT INTO `tomer` VALUES ('00011', '田一', '男', '12345678911');
INSERT INTO `tomer` VALUES ('00012 ', '田二', '男', '10345678910');
INSERT INTO `tomer` VALUES ('00013', '田三', '男', '12045678910');
INSERT INTO `tomer` VALUES ('00014', '田四', '男', '12305678910');
INSERT INTO `tomer` VALUES ('00015', '田五', '女', '12340678910');
INSERT INTO `tomer` VALUES ('00016', '田六', '女', '12345078910');
INSERT INTO `tomer` VALUES ('00017', '田七', '女', '12345608910');
INSERT INTO `tomer` VALUES ('00018', '田八', '女', '12345670910');
INSERT INTO `tomer` VALUES ('00019', '田九', '男', '12345678010');
INSERT INTO `tomer` VALUES ('00020', '暴徒', '男', '12345678920');
-- ----------------------------
-- Table structure for worke
-- ----------------------------
DROP TABLE IF EXISTS `worke`;
CREATE TABLE `worke` (
`W_id` varchar(10) NOT NULL,
`W_name` varchar(10) DEFAULT NULL,
`W_sex` varchar(4) DEFAULT NULL,
`W_age` int(11) DEFAULT NULL,
`W_salary` float DEFAULT NULL,
PRIMARY KEY (`W_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
-- ----------------------------
-- Records of worke
-- ----------------------------
INSERT INTO `worke` VALUES ('01', '张一', '男', '21', '5200');
INSERT INTO `worke` VALUES ('02', '张二', '男', '21', '5100');
INSERT INTO `worke` VALUES ('03', '张三', '男', '22', '5000');
INSERT INTO `worke` VALUES ('04', '张四', '男', '22', '4900');
INSERT INTO `worke` VALUES ('05', '张五', '男', '22', '4800');
INSERT INTO `worke` VALUES ('06', '张六', '女', '21', '5200');
INSERT INTO `worke` VALUES ('07', '张七', '女', '20', '5100');
INSERT INTO `worke` VALUES ('08', '张八', '女', '20', '5000');
INSERT INTO `worke` VALUES ('09', '张九', '女', '20', '5000');
INSERT INTO `worke` VALUES ('10', '不可以色色', '女', '20', '5000');
-- ----------------------------
-- View structure for tomer_t
-- ----------------------------
DROP VIEW IF EXISTS `tomer_t`;
CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `tomer_t` AS select `tomer`.`T_id` AS `T_id`,`tomer`.`T_name` AS `T_name`,`tomer`.`T_rsex` AS `T_rsex`,`tomer`.`T_phone` AS `T_phone` from `tomer` where (`tomer`.`T_rsex` = '女') ;
2.python代码
# 主菜单
def main():
# while死循环
while True:
# 打印主菜单
print('------------欢迎使用点餐系统------------\n本软件提供如下功能:')
lis = ['1. 查看菜单', '2. 查看顾客信息', '3. 查看员工信息', '4. 退出系统']
for i in lis:
print(i)
# 接收用户输入
a = int(input('请输入数字选择一项功能:'))
if a == 1:
print('开始点餐')
order_food()
continue
elif a == 2:
print('正在打印报表')
print_work()
continue
elif a == 3:
print('正在存储报表')
people()
continue
elif a == 4:
print('成功退出系统')
# 退出循环
break
else:
print('输入错误请重新输入!!')
continue
def order_food():
import pymysql
#打开数据库连接
db = pymysql.connect(host="localhost",user="root",password="123456",database="ks")
#使用cursor()方法获取操作游标
cursor = db.cursor()
#sql语句
sql = "select * from menus_oder"
try:
#执行sql语句
cursor.execute(sql)
#查询中的一个操作,获取所有记录
result = cursor.fetchall()
#打印表数据
for row in result:
O_id = row[0]
M_id = row[1]
M_name = row[2]
M_number = row[3]
print(O_id, M_id,M_name,M_number)
except:
print("Error!")
def print_work():
import pymysql
db = pymysql.connect(host="localhost",user="root",password="123456",database="ks")
cursor = db.cursor()
sql = "select * from tomer "
try:
cursor.execute(sql)
result = cursor.fetchall()
for row in result:
T_id = row[0]
T_name = row[1]
T_rxex = row[2]
T_phone = row[3]
print( T_id,T_name,T_rxex,T_phone)
except:
print("Error!")
def people():
import pymysql
db = pymysql.connect(host="localhost",user="root",password="123456",database="ks")
cursor = db.cursor()
sql = "select * from worke "
try:
cursor.execute(sql)
result = cursor.fetchall()
for row in result:
W_id = row[0]
W_name = row[1]
W_sex = row[2]
W_age = row[3]
W_salary = row[4]
print( W_id,W_name,W_sex,W_age,W_salary)
except:
print("Error!")
if __name__ == '__main__':
main()
Author:Poison
link:http://www.pythonblackhole.com/blog/article/79641/8874dcf888cd97c22cbf/
source:python black hole net
Please indicate the source for any form of reprinting. If any infringement is discovered, it will be held legally responsible.
name:
Comment content: (supports up to 255 characters)
Copyright © 2018-2021 python black hole network All Rights Reserved All rights reserved, and all rights reserved.京ICP备18063182号-7
For complaints and reports, and advertising cooperation, please contact vgs_info@163.com or QQ3083709327
Disclaimer: All articles on the website are uploaded by users and are only for readers' learning and communication use, and commercial use is prohibited. If the article involves pornography, reactionary, infringement and other illegal information, please report it to us and we will delete it immediately after verification!