I would like to have a connection between my python code and a SQL database. I have read several ways to do it , but I am failing to get the results.
conn =
You have to pass the parameters inside an iterable - commonly a tuple:
query = 'SELECT id,sing_name,bir_yr FROM singers_list WHERE bir_yr = %s'
curs.execute(query, (year, ))
Note that I've also replaced the ?
placeholder with %s
.
Also note that the MySQL driver would automatically handle the type conversion between Python and MySQL, would put quotes if necessary and escape the parameters to keep you safe from SQL injection attacks.