错误 1064:显示语法错误无法找到导致此错误的原因

时间:2021-05-26 07:37:35

标签: python mysql tkinter mysql-python mysql-error-1064

<块引用>

mysql.connector.errors.ProgrammingError: 1064 (42000): 你的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册,以获取在第 1 行的“%s”附近使用的正确语法

代码:

isFileMatching

2 个答案:

答案 0 :(得分:1)

你也可以试试这个:

cur.execute("DELETE FROM students WHERE roll_no=%s",
(
    self.Roll_No_var.get(),      # seperate your entries from the sql
))                               # code

--------

cur.execute("SELECT * FROM students WHERE example=%s LIKE %s ORDER BY ....",
(
     '%' + self.your_entries.get() + '%',     # there are different ways for mysql
     '%' + self.your_entries.get() + '%',     # make sure, that your table, you created matched, with your entries.
                                              #or you will get this mysql.errors
))

答案 1 :(得分:0)

delete_data() 中,cur.execute(...) 的第二个参数应该是一个元组或列表:

cur.execute("DELETE FROM students WHERE roll_no=%s", (self.Roll_No_var.get(),))

where 函数内的 SQL 语句中的 search_data() 字后应该有一个空格:

"select * from students where "+str(self.search_by.get())+" like '%"+str(self.search_text.get())+"%'"

使用 f-string 更具可读性:

sql = f"SELECT * FROM students WHERE {self.search_by.get()} LIKE %s"
cur.execute(sql, (f"%{self.search_text.get()}%",))
相关问题