【发布时间】:2021-04-14 20:03:45
【问题描述】:
当前收到错误“mysql.connector.errors.ProgrammingError: 1064 (42000): 您的 SQL 语法有错误;请查看与您的 MySQL 服务器版本相对应的手册,以了解在 '%s 附近使用的正确语法)' 在第 1 行",当我运行此代码时:
def initiate_sale():
while True:
cx_shopped_before = input('Has customer shopped with us before? Y/N: ')
if cx_shopped_before.upper() == 'Y':
cust_email = input('Please enter customers email address')
with mysql.connector.connect(host=HOSTNAME, user=USER_NAME, password=PASSWORD) as mysql_connection:
with mysql_connection.cursor() as mysql_cursor:
mysql_cursor.execute('USE florist')
query = "SELECT CusID, cus_fname, cus_lname FROM customer WHERE cus_email = (%s)"
mysql_cursor.execute(query, cust_email)
break
elif cx_shopped_before.upper() == 'N':
pass
else:
print('Invalid choice, use Y or N')
我相信它是一个简单的括号或逗号,因为它只是执行语句中元组中的一个项目,但我找不到在哪里。提前致谢
【问题讨论】:
标签: python mysql mysql-connector