I am developing python application which should work with database. I came along with one problem. In PHP I can make queries with variables directly just by $ sign, but in python I am writing this code:
query = "INSERT INTO shops (id, shop_id, shop_url, shop_name, shop_cat, datas)" + "VALUES("+count+", "+str(shop_id)+", "+shop_url+", "+shop_name+", "+shop_cat+", "+pdfs+datas+");"
Is there any method doing it like in PHP, I mean doing it inside one string?
You should never concatenate an SQL string like that. You are asking for an SQL injection.
Use the built in escaping in the DB API:
…and your query will be properly escaped.
In general in Python, you can use “+” to concatenate strings. You can also use printf-like syntax “Hello %s!” % “World” and the newer formatting syntax “Hello {0}”.format(‘World!’)