使用MySQLdb 插入变量数据
做个笔记
import MySQLdb
import time
#打开服务器连接
db = MySQLdb.connect("localhost", "count", "password?", "firedetect", charset='utf8' ) #firedetect 为数据库名
# 使用cursor()方法获取操作游标
cursor = db.cursor()
t = 's'
temper = 20
concen = 10
sql = "INSERT INTO test(time,temper,concen) values('%s','%s','%s')"%(t,temper,concen)
cursor.execute(sql)
cursor.connection.commit()