python的pymsql的使用
PHP中文网
PHP中文网 2017-04-17 17:41:15
0
1
317

我想写一个函数,能向指定的表中插入一些数据,但是参数怎么传递 不清楚,麻烦大家帮忙改一下,没加入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   
PHP中文网
PHP中文网

认证0级讲师

全部回复(1)
洪涛

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

sql = "INSERT INTO {} (date, high, low) VALUES(%s, %s, %s)".format(table)
cur.execute(sql, [date, high, low])
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板