首页 > python的pymsql的使用

python的pymsql的使用

我想写一个函数,能向指定的表中插入一些数据,但是参数怎么传递 不清楚,麻烦大家帮忙改一下,没加入table之前函数能正常使用

def mysql_insert(table,date,high,low):
    try:
           param=[table,date,high,low]
           sql="INSERT INTO table (date,high,low) VALUES(%s,%s,%s)"
           cur.execute(sql,param)
           conn.commit()
    except:
            return 0   

没用过pymysql,不过这样做可以实现你的功能:

sql = "INSERT INTO {} (date, high, low) VALUES(%s, %s, %s)".format(table)
cur.execute(sql, [date, high, low])
【热门文章】
【热门文章】