python之MySQL學習——防止SQL注入(參數化處理)

來源:互聯網
上載者:User

標籤:int   處理   use   .exe   word   exec   class   mit   參數   

 1 import pymysql as ps 2  3 # 開啟資料庫連接 4 db = ps.connect(host=‘localhost‘, user=‘root‘, password=‘123456‘, database=‘test‘, charset=‘utf8‘) 5  6 # 建立一個遊標對象 7 cur = db.cursor() 8  9 # 參數化處理10 sql = "INSERT INTO USER(NAME,PASSWORD) VALUES(%s,%s)"11 12 cur.execute(sql, (‘小黑‘, ‘123456‘))13 14 print("OK")15 16 # 提交事務(這個一定要主動提交,不然在資料庫中操作增、刪結果不改變)17 db.commit()18 19 # 關閉遊標20 cur.close()21 22 # 關閉資料庫23 db.close()

 

python之MySQL學習——防止SQL注入(參數化處理)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.