MySQLdb 操作数据库


Conn_IP = ""
Conn_UserName = ""
Conn_PassWord = ""
Conn_database = ""

conn = MySQLdb.connect(Conn_IP,Conn_UserName,Conn_PassWord,Conn_database)

cursor = conn.cursor()

val = {"k1":t,"k2":n}
ins_sql = "insert into 表(字段1,字段2) values(%(k1)s,%(k2)s)"

try:
cursor.execute(ins_sql,val)
conn.commit()
except:
conn.rollback()

conn.close()

posted on 2020-06-18 18:25  二十四岁半  阅读(130)  评论(0编辑  收藏  举报

导航