我一直在尝试使用针对不同客户每分钟进行的测试来填写我的数据库,但我们无法将我的日期格式化为datetime
字段中的时间。
格式应为YYYY-mm-dd HH:MM:SS
import MySQLdb as mdb
import datetime
con = mdb.connect('localhost', 'testuser', 'test623', 'xymon');
now = str((datetime.datetime.now()).strftime("%Y-%m-%d %H:%M:%S"))
print '#'+now+'#'
with con:
cur = con.cursor()
cur.execute("INSERT INTO download(time, client1,client2,client3,client4) VALUES('%s',1500,2500,70000,100000)") , (now)
con.commit()
值发生在数据库中,但错误只是0000-00-00 00:00:00
答案 0 :(得分:0)
你必须现在提供' to cur.execute调用,%s cur.execute周围没有引号(" INSERT INTO下载(时间,client1,client2,client3,client4)VALUES(%s,1500,2500,70000,100000)&#34 ;,现在)