Answer the question
In order to leave comments, you need to log in
How to work with pymysql?
Hello, I have a question that is quite difficult to state correctly. I don’t understand how I can effectively work with Pymysql in python. I know the python syntax well, mysql is worse, but I can work. But at work I have a lot of problems with the type of data loading in db. I had a project with which I started learning python, it was a bot on vk. There I used Json as a db, that is, Json with user data was next to the executable file, I opened it in code, read / wrote and saved. Naturally, this is not entirely correct, because you can make queries to the database and get the information I need, but I ran into some problems. The most incomprehensible of them is saving different data types:
def setdigit(self, id, data):
with self.connect:
cur = self.connect.cursor()
cur.execute(f"UPDATE DB.USERS SET {data.keys()[0]}={data[data.leys()[0]]} WHERE id={id}")
def setstring(self, id, data):
with self.connect:
cur = self.connect.cursor()
cur.execute(f"UPDATE DB.USERS SET {data.keys()[0]}='{data[data.leys()[0]]}' WHERE id={id}")
def setdigit(self, id, key, value):
with self.connect:
cur = self.connect.cursor()
cur.execute(f"UPDATE DB.USERS SET {key}={value} WHERE id={id}")
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question