以下内容正确打印结果,但我试图填充的mysql表中没有显示任何记录:
#!/usr/bin/python
import MySQLdb
import string
db = MySQLdb.connect(host="localhost",
user="user",
passwd="******",
db="test")
cur=db.cursor()
i = 0
for lt in string.ascii_lowercase:
dbinsert = """insert into dns(domain,A,MX,T,serial,ttl)
values('"""+lt+""".com',' 1.1.1."""+str(i)+"""\\n','10 mx1.somehost.com.\\n',
'@ "txt data"\\n',2013092001,300)"""
print dbinsert
i+=1
#cur=db.cursor()
try:
cur.execute(dbinsert)
db.commit
except MySQLdb.Error, e:
print e[0], e[1]
db.rollback()
db.close()
我在这里缺少什么?
答案 0 :(得分:0)
db.commit
应为db.commit()