导入模块
import pymysql
conn = pymysql.connect(
user = "root",
db = "day36",
host = "127.0.0.1",
post = 3306,
charset = "utf8"
autocommit = True #自动提交确认
)
cursor = conn.cursor(cursor = pymysql.cursors.DictCursor)
#以字典形式输出出来
#获取用户输入的用户名和密码,然后取数据库中校验
username = input("usename>>:").strip()
password = input("password>>:").strip()
sql = select * from userinfo where name = %s and password = %s"
print(sql)
增
sql = "insert into userinfo(name,password,dep_id) values ("jason",789,1)"
改
sql = "update userinfo set name = "egons" where id = 6"
删除
sql = "delete from userinfo where id = 1"
res = cursor.execute(sql)
conn.commit() #确认当前操作,真正的同步到数据库
如果真想操作,必须有一步确认操作。