MYSQL——pymysql模块[Python常见问题]

 

1、基本规则及其input命令

import pymysql

conn=pymysql.connect(host="127.0.0.1",port=3306,user="root",password="123",database="db4",charset="utf8mb4")
#游标
cursor=conn.cursor() #执行完毕返回的结果集默认以元组显示

# cursor.execute("insert into user(name,pwd) values("egon","123"),("tom","456"),("jack","111");")

# sql="insert into user(name,pwd) values("%s","%s");" %("lili","123")
# cursor.execute(sql)

# %s不要加引号
# cursor.execute("insert into user(name,pwd) values(%s,%s);",("kkk","123"))


username = input("username>>>: ").strip()
password = input("password>>>: ").strip()
# sql = "select * from user where name="%s" and pwd="%s"" %(username,password)
# select * from user where name="egon" -- hello" and pwd="%s"
# select * from user where name="xxx" or 1=1 -- hello" and pwd="%s";
# rows=cursor.execute(sql)

rows=cursor.execute("select * from user where name=%s and pwd=%s",(username,password))

if rows:
    print("ok")
else:
    print("no")

conn.commit()
cursor.close()
conn.close()
hmoban主题是根据ripro二开的主题,极致后台体验,无插件,集成会员系统
自学咖网 » MYSQL——pymysql模块