I have a python dict like this:
my_dict = {'find': ['http://time.com', 'http://find.com'], 'time': ['http://any.com', 'http://www.tim.com', 'http://mine.in']...}
I want to insert keys
and values
of dictionary my_dict
in two different columns of a mysql table. The columns names are term
and urls
respectively. I have three columns for now: id
, term
, urls
and I want to insert each keys and values pairs in different rows.
I want to store the links in urls
as seperated by commas. The website links in the values of my_dict must be stored seperated by commas like http://time.com, http://mine.com.
I tried to insert in the following manner
for i in my_dict.items():
keys = i[0]
values = i[1]
sql = """INSERT INTO index_table (term, urls) VALUES (%s, %s)"""
cursor.execute(sql, (keys, values))
But it shows the following error:
(1064, "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 '))' at line 1")