简体   繁体   English

如何使用python将变量插入MySQL表

[英]How to insert variable to MySQL table using python

I have looked all over stack overflow and none of the answers works.我已经查看了堆栈溢出,但没有一个答案有效。 This is the code below:这是下面的代码:

var = ""


sql = "INSERT INTO yyc_central (NO) VALUES %s"

mycursor.execute(sql, var)

I am using mysql.connector to connect to my database.我正在使用 mysql.connector 连接到我的数据库。 I am also getting an error that says:我也收到一条错误消息:

You have an error in your SQL syntax;您的 SQL 语法有错误; check the manual that corresponds to your MySQL server version for the right syntax to use near '?'检查与您的 MySQL 服务器版本相对应的手册,了解在“?”附近使用的正确语法。 at line 1在第 1 行

Don't mind "line 1" I really need help please and thank you.不要介意“第 1 行”,我真的需要帮助,谢谢。

python is somewhat peculiar with only 1 parameter, so python有点奇怪,只有1个参数,所以

var = ""


sql = "INSERT INTO yyc_central (NO) VALUES (%s)"

mycursor.execute(sql, (var,))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM