python – mysql.connector – SQL语法中有错误;第1行’%s’附
发布时间:2020-12-20 12:00:33 所属栏目:Python 来源:网络整理
导读:我正在引用 this page以便对我的数据库进行SELECT查询.但是,我收到此错误: 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 righ
我正在引用
this page以便对我的数据库进行SELECT查询.但是,我收到此错误:
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 '%s' at line 1 以下是带有问题的代码部分: import mysql.connector cnx = mysql.connector.connect(user='xxxx',password='yyyy',host='zzzz.us-west-2.rds.amazonaws.com',database='iiii') cursor = cnx.cursor() # ... givenUsername = 'testUser123' checkUserAuthQuery = ("SELECT password FROM UserAuth WHERE username = %s") userAuthInfo = (givenUsername) cursor.execute(checkUserAuthQuery,userAuthInfo) # ... 笔记: 解决方法
您缺少逗号以使userAuthInfo成为元组.将其更改为:
userAuthInfo = (givenUsername,) (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |