使用flakext.mysql在mysql中插入数据

44u64gxh  于 2023-02-28  发布在  Mysql
关注(0)|答案(1)|浏览(67)

我正在做一个简单的网页表单,但我尝试运行此代码它给了我一个错误我是新的python我不知道这个错误意味着什么,无法找到在线解决方案。这里是一个代码:

from flaskext.mysql import MySQL
from datetime import date
from dateutil import parser
mysql = MySQL()
app = Flask(__name__)
app.config['MYSQL_DATABASE_USER'] = 'mraghib'
app.config['MYSQL_DATABASE_PASSWORD'] = 'raghib10'
app.config['MYSQL_DATABASE_DB'] = 'fyp'
app.config['MYSQL_DATABASE_HOST'] = 'localhost'
mysql.init_app(app)

if __name__ == ("__main__"):
    cursor = mysql.connect().cursor()
    print(cursor.execute("select * from companylist"))
    addcompanyList= ("INSERT INTO CompanyList (Ticker, CompanyName, SECP_Sector_Code, SectorName,OutstandingShares,DemoSheetName,Years) ""VALUES (%s, %s ,%int, %s,%int, %s, %s)")
    datacompanyList = ("sdasd","adsda",142,"daasda",32,"sdadas",date(1977, 6, 14))

    cursor.execute (addcompanyList,datacompanyList)

roejwanj

roejwanj1#

试试这个:

ddcompanyList= ("""INSERT INTO CompanyList (Ticker, CompanyName,SECP_Sector_Code, SectorName,OutstandingShares,DemoSheetName,Years) VALUES(%s, %s ,%s, %s, %s, %s, %s)""")

相关问题