zoukankan      html  css  js  c++  java
  • Python--day45--pymysql模块初识以及SQL注入

    pymysql模块学习路径:增删改的时候一定要conn.commit()

    pymysql模块实现登录功能:

     1 import pymysql
     2 
     3 user = input("username:")
     4 pwd = input("password:")
     5 
     6 conn = pymysql.connect(host="localhost",user='root',password='123456',database="db5")
     7 #游标
     8 cursor = conn.cursor()
     9 #连接数据库成功
    10 
    11 
    12 #不要自己做字符串拼接,这样是错误的,会造成数据库中没有的账号也会登录成功
    13 sql = "select * from userinfo where username=%s and password=%s "
    14 #execute会自己帮我们拼接字符串
    15 # cursor.execute(sql,{'u':user,'p':pwd})
    16 cursor.execute(sql,[user,pwd])
    17 #取结果的第一条
    18 result = cursor.fetchone()
    19 
    20 if result:
    21     print("登录成功")
    22 else:
    23     print("登录失败")
    24 
    25 #关闭数据库
    26 cursor.close()
    27 conn.close()

    运行结果:

  • 相关阅读:
    HDU 5319 Painter
    HDU 5328 Problem Killer
    HDU 5327 Olympiad
    HDU 5339 Untitled
    HDU 5335 Walk Out
    HDU 5317 RGCDQ
    HDU 5326 Work
    CF GYM 100703A Tea-drinking
    CF GYM 100703B Energy Saving
    CF GYM 100703F Game of words
  • 原文地址:https://www.cnblogs.com/xudj/p/10380865.html
Copyright © 2011-2022 走看看