02查詢數(shù)據(jù)


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):

#關(guān)閉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('請輸入功能對應(yīng)的序號')

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)用這個(gè)對象run方法,并且使它運(yùn)行

tcl.run()

if __name__ == '_main_:

main()

#刪的方案。方案一 (——真刪——)。將所有分類下商品的類別置為NULL。再刪除分類

#方案二。 (---假刪---) 添加是否顯示該分類的字段is_show? 更新該字段為隱藏

#SQL注入

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容