Python Variables In MySQL
I would like to use Python variables as table name, column name and value but this query don't working: def dodaj_do_bazy (wartosc, miejsce, tabela): # Open database connection db
Solution 1:
from my tests...
MySQLdb expects tuples as variables, so enclose in parenthesis
cursor.execute('INSERT INTO %s (%s) VALUES (%s)' % (tabela, miejsce, wartosc))
Does this help?
Solution 2:
found it here on SO:
This is working for me now (python 2.7.6, MariaDB)
sql = """INSERT INTO %s (%s) VALUES (%s)""" % ( tabela, miejsce, wartosc )
And your insert value have to be quoted wpis_email = """ 'whatever' """
First try without the try/except
, as this eats any error messages
Post a Comment for "Python Variables In MySQL"