構造execute參數列表,讓模塊自動去拼裝查詢字符串,可防止SQL注入現象發生,代碼:
# 安全方式find_name = input("請輸入您要查詢商品的名稱:")# 構造參數列表params = [find_name]# 執行select語句,并返回受到影響的行數;查詢數據count = cs1.execute('select * from goods where name=%s;' % params)
# 安全方式
find_name = input("請輸入您要查詢商品的名稱:")
# 構造參數列表
params = [find_name]
# 執行select語句,并返回受到影響的行數;查詢數據
count = cs1.execute('select * from goods where name=%s;' % params)