Как производить поиск в БД MySQL по 2 параметрам Python
Нужно проводить поиск по 2 параметрам в бд MySQL используя Python, как это можно осуществлять?
mycursor.execute(f"SELECT id, mention FROM discord_user where id={str(user.id)},mention={str(user.mention)}")
mycursor.execute(f"SELECT id, mention FROM discord_user where id={str(user.id)} AND mention={str(user.mention)}")
Примеры сверху выдают одну и ту же ошибку:
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: 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 '=<@!401653705927294976>' at line 1
Ответы (1 шт):
Автор решения: gil9red
→ Ссылка
Попробуйте составить запрос, используя биндинг:
mycursor.execute("SELECT id, mention FROM discord_user where id=%s AND mention=%s", (user.id, user.mention))