import MySQLdb
def Network():
dict = {'CISCO' : 'NEXUS', 'JUNIPER' : 'JUNO', 'Alcatel' : 'Alc' }
#len(dict)
return (dict)
def db_store(variable):
con = MySQLdb.connect("localhost","root","root","fs_company" )
cur = con.cursor()
for key,value in variable.items():
cur.execute('''INSERT into google (name, company) values (%s, %s)''', (key, value))
con.commit()
cur.execute("""SELECT * FROM google""")
variable = cur.fetchall()
#print variable
variable = Network()
db_store(variable)
I have above code to store the data to mysql database, I want to retrieve the data from database in dictionary format. need help for the same
%s. That could leed to formatting problems. Replace them by?, then the databse does the formatting.