from pymysql import connect
class TCL (object):
def __init__(self):
#創(chuàng)建Connection連接
self.conn = connect(host = 'localhost',port = 3306,user = 'root' ,password = 'hezhuang',database = 'TCL',charset = 'utf8')
#? 獲得Cursor對象
self.cursor = conn.cursor()
def __del__(self):
關閉Cursor對象
self.cursor.close()
self.conn.close()
def execute_sql(self,sql):
self.cursor.execute(sql)
for temp in self.cursor.fetchall():
print(temp)
def show_all_items(self):
顯示所有商品
sql = 'select * from goods;'
self.execute_sql(sql)
def show_cates(self):
sql = 'select name from goods_cates;'
self.execute_sql(sql)
def show_brands(self):
sql = 'select name from goods_brands;'
self.execute_sql(sql)
@staticmethod
def print_menu(self):
print('---------TCL--------')
print('1:所有商品')
print('2:所有的商品分類')
print('3:所有商品品牌分類')
return input('請輸入功能對應的序號')
def run(self):
while? True:
num = self.print_menu()
if num == '1':
查詢說有商品
self.show_brands()
elif num == ‘2’:
#查詢分類
self.show_brands()
elif num == '3':
查詢品牌分類
self.show_brands()
elif num == '4':
查詢品牌分類
self.show_brands()
else:
print('輸入有誤,請重新輸入')
def main():
#1 創(chuàng)建TCL商城對象
tcl = TCL()
#2 調(diào)用這個對象run方法,并且使它運行
tcl.run()
if __name__ == '_main_:
main()
#刪的方案。方案一 (——真刪——)。將所有分類下商品的類別置為NULL鲸湃。再刪除分類
#方案二。 (---假刪---) 添加是否顯示該分類的字段is_show? 更新該字段為隱藏