2
import MySQLdb
import time
try:
db = MySQLdb.connect(host="", #your host, usually localhost
user="", #your username
passwd="", #your password
db="") #name of the data base
cur = db.cursor()
except mysql.connector.Error as err:
print("Something went wrong: {}".format(err))
SQL = "INSERT INTO TBL_PYTest (Time) VALUES (%s)"
Count = 0
while Count < 5:
UTime = int(time.time())
print UTime
cur.execute(SQL, (UTime))
time.sleep(5)
Count = Count + 1
print Count
为什么不能正常工作?它的打印正确但数据库保持空白。 我检查了数据库,它似乎很好 所有的细节都是正确的Python没有插入MySQL
感谢您修复了此问题的其他人,请看这里:http://dev.mysql.com/doc/connector-python/en/connector-python-api-mysqlconnection-commit.html – 2014-10-09 09:36:38