时间:2021-07-01 10:21:17 帮助过:12人阅读
pymysql模块:
pip3 install pymysql -i https://pypi.douban.com/simple
Python模块:对数据库进行操作(SQL语句)
1. Python实现用户登录
2. MySQL保存数据
- 连接、关闭(游标)
- execute() -- SQL注入
- 增删改: conn.commit()
- fetchone fetchall
- 获取插入数据自增ID
# 增加,删,该
# conn = pymysql.connect(host="localhost",user=‘root‘,password=‘‘,database="db666")
# cursor = conn.cursor()
# sql = "insert into userinfo(username,password) values(‘root‘,‘123123‘)"
# 受影响的行数
# r = cursor.execute(sql)
# # ******
# conn.commit()
# cursor.close()
# conn.close()
# conn = pymysql.connect(host="localhost",user=‘root‘,password=‘‘,database="db666")
# cursor = conn.cursor()
# # sql = "insert into userinfo(username,password) values(%s,%s)"
# # cursor.execute(sql,(user,pwd,))
#
# sql = "insert into userinfo(username,password) values(%s,%s)"
# # 受影响的行数
# r = cursor.executemany(sql,[(‘egon‘,‘sb‘),(‘laoyao‘,‘BS‘)])
# # ******
# conn.commit()
# cursor.close()
# conn.close()
# 查
# conn = pymysql.connect(host="localhost",user=‘root‘,password=‘‘,database="db666")
# cursor = conn.cursor(cursor=pymysql.cursors.DictCursor)
# sql = "select * from userinfo"
# cursor.execute(sql)
# cursor.scroll(1,mode=‘relative‘) # 相对当前位置移动
# cursor.scroll(2,mode=‘absolute‘) # 相对绝对位置移动
# result = cursor.fetchone()
# print(result)
# result = cursor.fetchone()
# print(result)
# result = cursor.fetchone()
# print(result)
# result = cursor.fetchall()
# print(result)
# result = cursor.fetchmany(4)
# print(result)
# cursor.close()
# conn.close()
# 新插入数据的自增ID: cursor.lastrowid
# import pymysql
# conn = pymysql.connect(host="localhost",user=‘root‘,password=‘‘,database="db666")
# cursor = conn.cursor()
# sql = "insert into userinfo(username,password) values(‘asdfasdf‘,‘123123‘)"
# cursor.execute(sql)
# conn.commit()
# print(cursor.lastrowid)
# cursor.close()
# conn.close()
pymsql
标签:行操作 pre 获取 pwd mysq 增删改 影响 保存 sel