繁体   English   中英

错误 1064 (42000):您的 SQL 语法中存在错误,接近使用 %s

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

我不知道我做错了什么,但错误是:error 1064 (42000): You have an error in your SQL syntax; 检查与您的 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()

暂无
暂无

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

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