B
B
bluefasik2021-12-23 16:21:53
Python
bluefasik, 2021-12-23 16:21:53

How to make sql not throw syntax error?

I wrote a function that checks if there is an element in the database by its link

def check_advestisement(self, user_id, adv_url):
    sql = "SELECT * FROM `{}` WHERE `Ссылка на объявление`={}".format(user_id, adv_url)
    self.adv_cursor.execute(sql)
    myr = self.adv_cursor.fetchone()
    print(myr)

I tried different ways, but everything gives me one error: mysql.connector.errors.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 ':// www.google.com/ ...' at line 1

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Gornostaev, 2021-12-23
@bluefasik

Do not use string formatting to form queries.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question