from pymysql import *
class JD(object):
def init(self):
# 创建connection链接
self.conn = connect(host=‘127.0.0.1’,port=8080, usser=‘root’, password=‘smoy’, database=‘jianda’, charset=‘utf8’)
# 获得cursor对象
self.cursor = self.conn.cursor()
def __del__(self):
# 关闭cursor对象, 当程序结束 Python解释器自动调用此方法
self.cursor.close()
self.conn.close()
def execute_sql(self, sql):
self.cursor.execute(sql)
fro 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_brands;"
self.execute_sql(sql)
def show_brands(self):
sql = "select name from goods_brands;"
self.execute_sql(sql)
def add_brands(self):
item_name = input("输入商品分类的名称:")
sql = """insert into goods_brands (name) values ("%s")&#