import pymysql
client = pymysql.connect("ip","user","password","database")
# 得到一个可以执行SQL语句的光标对象
cursor = conn.cursor()
# 定义要执行的SQL语句
sql = ""
# 执行SQL语句
cursor.execute(sql)
# 提交事务
client.commit()
#该方法获取下一个查询结果集。结果集是一个对象
results1 = cursor.fetchone()
#接收全部的返回结果行.
results2 = cursor.fetchall()
#这是一个只读属性,并返回执行execute()方法后影响的行数。
row=cursor.rowcount()
# 关闭光标对象
cursor.close()
# 发生错误时回滚
db.rollback()
# 关闭数据库连接
client.close()
Last modification:October 11th, 2019 at 11:12 pm
If you think my article is useful to you, please feel free to appreciate