python 在写入mysql的时候如何引用变量
例如:year=2015time=11:23call=1db=MySQLdb.connect("localhost","root","root","net")cursor...
例如:
year = 2015
time = 11:23
call = 1
db = MySQLdb.connect("localhost","root","root","net" )
cursor = db.cursor()
cursor.execute(insert into call_number VALUES (%year,%time,%call)
写入数值到 mysql,但是不成功。
求大神,如何调用定义的函数。 展开
year = 2015
time = 11:23
call = 1
db = MySQLdb.connect("localhost","root","root","net" )
cursor = db.cursor()
cursor.execute(insert into call_number VALUES (%year,%time,%call)
写入数值到 mysql,但是不成功。
求大神,如何调用定义的函数。 展开
2个回答
展开全部
conn = MySQLdb.connect("localhost","root","123456","test",charset = 'utf8')
cur = conn.cursor()
sql = "insert into sinfo(hostname,user,ip) values('%s','%s','%s')" %(host,username,ip)
try:
cur.execute(sql)
conn.commit()
except:
conn.rollback()
conn.close()
cur = conn.cursor()
sql = "insert into sinfo(hostname,user,ip) values('%s','%s','%s')" %(host,username,ip)
try:
cur.execute(sql)
conn.commit()
except:
conn.rollback()
conn.close()
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询