Misty rain
言必行,行必果。
"""
@Author:Misty rain(ZhangHao)
@E-mail:676817831@qq.com
@FileName:connectmysql.py
@Software:PyCharm
@Desc:连接mysql数据库
"""
import pymysql
def connect():
db = pymysql.connect(host='localhost',
user='root',
password='123456',
port=3306,
database='test')
cursor = db.cursor()
cursor.execute("SELECT VERSION()")
data = cursor.fetchone()
db.commit()
print('已连接mysql数据库:' + data[0])
return db
# 插入语句
def insert(sql, args):
conn = connect()
cur = conn.cursor()
result = cur.execute(sql, args)
print(result)
conn.commit()
cur.close()
conn.close()
# 插入多条
def insert_many(sql, args):
conn = connect()
cur = conn.cursor()
result = cur.executemany(query=sql, args=args)
print(result)
conn.commit()
cur.close()
conn.close()
# 更新操作
def update(sql, args):
conn = connect()
cur = conn.cursor()
result = cur.execute(sql, args)
print(result)
conn.commit()
cur.close()
conn.close()
# 删除数据
def delete(sql, args):
conn = connect()
cur = conn.cursor()
result = cur.execute(sql, args)
print(result)
conn.commit()
cur.close()
conn.close()
# 查询所有数据
def queryall(sql, args):
conn = connect()
cur = conn.cursor()
cur.execute(sql, args)
results = cur.fetchall()
conn.commit()
cur.close()
conn.close()
return results
# 查询首条数据
def queryone(sql, args):
conn = connect()
cur = conn.cursor()
cur.execute(sql, args)
results = cur.fetchone()
conn.commit()
cur.close()
conn.close()
return results
if __name__ == '__main__':
# 插入一条
# sql = 'INSERT INTO user VALUES(%s,%s,%s,%s,%s,%s)'
# insert(sql, (None, 'test', '123456', '10', '15757191674', 'hangzhou'))
# # 插入多条
# sql = 'INSERT INTO user VALUES(%s,%s,%s,%s,%s,%s)'
# args = [(None, 'test', '123456', '10', '15757191674', 'hangzhou'),
# (None, 'test', '123456', '10', '15757191674', 'hangzhou'),
# (None, 'test', '123456', '10', '15757191674', 'hangzhou')]
# insert_many(sql, args)
# # 更新
# sql = 'UPDATE user SET username=%s WHERE userid = %s;'
# args = ('haha', '9')
# update(sql, args)
# 删除
# sql = 'DELETE FROM user WHERE userid = %s;'
# args = ('10',) # 单个元素的tuple写法
# delete(sql, args)
# 查询全部数据
# sql = 'SELECT * FROM user'
# result = queryall(sql,None)
# print(result)
# 查询首条数据
sql = 'SELECT * FROM user WHERE username = %s'
args = ('test',)
result = queryone(sql, args)
print(result)
该类可作为mysql数据库操作的公共方法,具体的操作代码中已经明确标注。
备案号: 浙ICP备2021040483号
1
1
1
1
1
1
1
-5) OR 65=(SELECT 65 FROM PG_SLEEP(15))--
1
1
1
1
1
1
1
1
1
1
1
1
1
1
{!{data:image/webp;base64,UklGRsAEAABXRUJQVlA4WAoAAAAwAAAADwQAKwEASUNDUBgCAAAAAAIYAAAAAAQwAABtbnRyUkdCIFhZWiAAAAAAAAAAAAAAAABhY3NwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQAA9tYAAQAAAADTLQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAlkZXNjAAAA8AAAAHRyWFlaAAABZAAAABRnWFlaAAABeAAAABRiWFlaAAABjAAAABRyVFJDAAABoAAAAChnVFJDAAABoAAAAChiVFJDAAABoAAAACh3dHB0AAAByAAAABRjcHJ0AAAB3AAAADxtbHVjAAAAAAAAAAEAAAAMZW5VUwAAAFgAAAAcAHMAUgBHAEIAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAFhZWiAAAAAAAABvogAAOPUAAAOQWFlaIAAAAAAAAGKZAAC3hQAAGNpYWVogAAAAAAAAJKAAAA+EAAC2z3BhcmEAAAAAAAQAAAACZmYAAPKnAAANWQAAE9AAAApbAAAAAAAAAABYWVogAAAAAAAA9tYAAQAAAADTLW1sdWMAAAAAAAAAAQAAAAxlblVTAAAAIAAAABwARwBvAG8AZwBsAGUAIABJAG4AYwAuACAAMgAwADEANkFMUEgdAAAAAQcQEREQkCT9/09G9D/jP//5z3/+85///Of/XwAAVlA4IFwCAACwRQCdASoQBCwBP3G42WW0ryunIAgCkC4JaW7hd2EbQAnsA99snIe+2TkPfbJyHvtk5D32ych77ZOQ99snIe+2TkPfbJyHvtk5D32ych77ZOQ99snIe+2TkPfbJyHvtk5D32ych77ZOQ99snIe+2TkPfbJyHvtk5D32ych77ZOQ99snIe+2TkPfbJyHvtk5D32ych77ZOQ99snIe+2TkPfbJyHvtk5D32ych77ZOQ99snIe+2TkPfbJyHvtk5D32ych77ZOQ99snIe+2TkPfbJyHvtk5D32ych77ZOQ99snIe+2TkPfbJyHvtk5D32ych77ZOQ99snIe+2TkPfbJyHvtk5D32ych77ZOQ99snIe+2TkPfbJyHvtk5D32ych77ZOQ99snIe+2TkPfbJyHvtk5D32ych77ZOQ99snIe+2TkPfbJyHvtk5D32ych77ZOQ99snIe+2TkPfbJyHvtk5D32ych77ZOQ99snIe+2TkPfbJyHvtk5D32ych77ZOQ99snIe+2TkPfbJyHvtk5D32ych77ZOQ99snIe+2TkPfbJyHvtk5D32ych77ZOQ99snIe+2TkPfbJyHvtk5D32ych77ZOQ99snIe+2TkPfbJyHvtk5D32ych77ZOQ99snIe+2TkPfbJyHvtk5D32ych77ZOQ99snIe+2TkPfbJyHvtk5D32ych77ZOQ99snIe+2TkPfbJyHvtk5D32ych77ZOQ99snIe+2TkPfbJyHvtk5D32xwAAD+/60eAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA}!}
1
1
1
1
1
1
1
1
555
-1)) OR 428=(SELECT 428 FROM PG_SLEEP(15))--
1
555
1
1
1
555
555
555
555
555
555
555
555
555
1
1
1
1
1
1
1
1
1
1
1
1
response.write(9882919*9204918)
'+response.write(9882919*9204918)+'
1
1
1
1
-1; waitfor delay '0:0:15' --
1
1
1
1
{!{data:image/webp;base64,UklGRsAEAABXRUJQVlA4WAoAAAAwAAAADwQAKwEASUNDUBgCAAAAAAIYAAAAAAQwAABtbnRyUkdCIFhZWiAAAAAAAAAAA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