标签:sql语句 def mys exec 获取 result host 元组 ret
import pymysql
pymysql.connect(参数列表)
cursor =conn.cursor()
row_count = cursor.execute(sql)
result = cursor.fetchall()
conn.commit()
conn.rollback()
cursor.close()
conn.close()
def get_conn():
"""
:return: 连接,游标
"""
#创建连接
conn = pymysql.connect(host ="127.*.*.*",
user ="**",
password ="123456",
db ="**",
charset ="utf8")
#创建游标,默认是元组类型
cursor = conn.cursor() # 执行完毕返回结果集默认以元组显示
return conn,cursor
def close_conn(conn,cursor):
if cursor:
cursor.close()
if conn:
conn.close()
-------------------------------
conn,cursor= get_conn()
conn.rollback()
conn.commit()
标签:sql语句 def mys exec 获取 result host 元组 ret
原文地址:https://www.cnblogs.com/codehao/p/12629590.html