错误 1064 (42000):您的 SQL 语法接近使用 %s 时出错

error 1064 (42000) : You have an error in your SQL syntax near to use %s

我不知道我做错了什么,但错误是:错误 1064 (42000): 您的 SQL 语法有误;检查手册 对应于您的 MySQL 服务器版本,以便使用正确的语法 在“%s”附近

def forget_password_window(self):
        if self.Mail_address.get()=="":
            messagebox.showerror("Erreur", "Veuillez rentrer une adresse mail valide.", parent=self.app)
        else:
            try:
                mydb = mysql.connector.connect(
                    host = "localhost",
                    user = "username",
                    password = "pwd",
                    auth_plugin='mysql_native_password',
                    database = "mydb"
                )
                cursor = mydb.cursor()
                cursor.execute("""SELECT * FROM Employee WHERE employee_address=%s """,(self.Mail_address.get()))
                row = cursor.fetchone()

我在上面的代码中编写了这段代码:

def connexion(self):
        if self.Mail_address.get()=="" or self.Password.get()=="":
            messagebox.showerror("Erreur", "Veuillez saisir l'adresse mail et le mot de passe !", parent=self.app)
        else :
            try:
                mydb = mysql.connector.connect(
                    host = "localhost",
                    user = "username",
                    password = "pwd",
                    auth_plugin='mysql_native_password',
                    database = "mydb"
                )
                cursor = mydb.cursor()
                cursor.execute("""SELECT * from Employee WHERE employee_address=%s and employee_matricule=%s""",(self.Mail_address.get(), self.Password.get()))
                row = cursor.fetchone()

此代码有效。 所以我知道为什么这段代码有效而第一个无效。 需要帮忙 !谢谢!

MySQL 连接器至少需要一个包含 2 个维度的列表作为参数

所以将您的代码更改为

def forget_password_window(self):
    if self.Mail_address.get()=="":
        messagebox.showerror("Erreur", "Veuillez rentrer une adresse mail valide.", parent=self.app)
    else:
        try:
            mydb = mysql.connector.connect(
                host = "localhost",
                user = "username",
                password = "pwd",
                auth_plugin='mysql_native_password',
                database = "mydb"
            )
            cursor = mydb.cursor()
            cursor.execute("""SELECT * FROM Employee WHERE employee_address=%s """,(self.Mail_address.get(),))
            row = cursor.fetchone()