Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/342.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python MySQL连接器选择变量_Python_Mysql_Sql - Fatal编程技术网

Python MySQL连接器选择变量

Python MySQL连接器选择变量,python,mysql,sql,Python,Mysql,Sql,我有一个小小的疑问: id = 'TESTID' sql = "SELECT ID,PASSWORD FROM USERS WHERE ID = %s" cursor.execute(sql,(id)) 我有一个错误: mysql.connector.errors.ProgrammingError: 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQ

我有一个小小的疑问:

id = 'TESTID'
sql = "SELECT ID,PASSWORD FROM USERS WHERE ID = %s"
cursor.execute(sql,(id))
我有一个错误:

mysql.connector.errors.ProgrammingError: 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'TESTID''' at line 1
我知道这是关于双引号的。我有多个其他的查询运行得很好,但它们有3个参数

例如:

id = 'TESTID'
GR = 'TEST'
name = 'HELLO'
last_name = 'WORLD'
sql = "INSERT INTO USERS (ID,GR,name,last_name) VALUES (%s,%s,%s,%s)"
cursor.execute(sql,(id,gr,name,last_name))
这一款在开头没有3个双引号,结尾没有3个其他双引号,运行非常完美,所以我不知道现在该怎么办


谢谢。

在python中,您应该记住的一点是
(7)
7
相同。对于长度为1的元组,您必须说
(7,)
(注意重要的尾随逗号)

因此,改变这一行:
cursor.execute(sql,(id))
cursor.execute(sql,(id,)

试试
sql=“从id=?”的用户选择id,密码”