I worked a little with MySQLDB in Python and thought I understood how it works. But now I want to define my own method to be more flexible. Read the code....
import MySQLdb as mydb
class DB(object):
def read(self, slct, frm):
connection = mydb.connect("123.12.34.56", "user", "pass", "foo")
cursor = connection.cursor()
cursor.execute("SELECT %s FROM %s", (slct, frm))
print cursor.fetchall()
connection.close()
if __name__ == '__main__':
db = DB()
db.read("*", "bar")
This throws me a SQL Syntax Error. Why can't I use it this way?
ProgrammingError: (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 ''bar'' at line 1")