发布网友 发布时间:2022-04-10 21:44
共3个回答
懂视网 时间:2022-04-11 02:05
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
热心网友 时间:2022-04-10 23:13
参数: autoCommit - 为 true 表示启用自动提交模式;为 false 表示禁用该模式热心网友 时间:2022-04-11 00:31
Java MySQL 驱动是 True