关于python使用MySQLdb新增操作

来源:互联网 发布:淘宝充值平台怎么提现 编辑:程序博客网 时间:2024/06/06 02:25
import MySQLdbfrom time import ctimeconn = MySQLdb.connect(host="localhost",user="root",passwd="",db="python")cursor = conn.cursor()sql = """INSERT INTO python.py_user_test            (username,             PASSWORD,             fstcreate)SELECT  username,  PASSWORD,  fstcreateFROM python.py_user"""try:    res = cursor.execute(sql)    print "success"    conn.commit()except:    print "error"    conn.rollback()    conn.close()


0 0
原创粉丝点击