Answer the question
In order to leave comments, you need to log in
FetchAll, how to display a value from MySql and put it in a variable (AioMysql, PyMysql)?
I'm using Python, the script is below:
await cur.execute("SELECT `user_id` FROM `admins` WHERE id = %s", (f'{id}'))
sql = cur.fetchall()
print(sql)
Answer the question
In order to leave comments, you need to log in
You need to use a tuple to pass parameters. Just adding parentheses to a value doesn't make it a tuple, you need to add a comma: (id, )
According to the query, only one value is required, so you can use fetchone (returns the first row of the result).
await cur.execute("SELECT `user_id` FROM `admins` WHERE id = %s", (id, ))
sql = cur.fetchone()
if sql:
user_id = sql[0]
print(user_id)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question