我不知道我做錯了什么,但錯誤是:錯誤 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()
此代碼正在作業。所以我想知道為什么這段代碼有效而第一個無效。需要幫忙 !謝謝 !
uj5u.com熱心網友回復:
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()
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/375694.html
