import MySQLdb
id=0
class SQL():
conn=MySQLdb.connect(host="localhost",
port=3306,
user="root",
passwd="123456",
db="test",
charset="utf8",)

def insert(self,name,time,content): #函数的调用
cur=self.conn.cursor()
global id
id+=1
#cur.execute("create table pinglun (id int ,name text,time text,content text)")

cur.execute("insert into pinglun VALUES ('%s' ,'%s','%s','%s')"%(id,name,time,content))
cur.close()
self.conn.commit()

mysql=SQL()#实例化类



mysql.insert(内容)
mysql.conn.close()