查询数据

from pymysql import connect

class TCL (object):

def __init__(self):

#创建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 创建TCL商城对象

tcl = TCL()

#2 调用这个对象run方法,并且使它运行

tcl.run()

if __name__ == '_main_:

main()

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容