python MySQLdb模块

https://www.cnblogs.com/franknihao/p/7267182.html

 

另外关于db这个连接对象,除了可以实例化一个游标对象之外,还可以进行commit(),rollback()等操作。

SQL = "DELETE FROM Client WHERE level < %d"
db = MySQLdb.connect(xxxxx)
cursor = db.cursor()
try:
  cursor.execute(SQL,(2,))
  db.commit()
except Exception,e:
  db.rollback()
finally:
  cursor.close()
  db.close()

 

posted @ 2019-02-20 20:06  凯文队长  阅读(221)  评论(0编辑  收藏  举报