次のコードで mysql のテーブルを更新するために、 string に列名があります。
cursor.execute("""update websites SET %s = %s where weblink = %s""",(key,value,x))
エラーが発生します:
_mysql_exceptions.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 ''blog' = 1 where weblink = 'http://blogspot.com/'' at line 1")
キー、値 = 'ブログ'、2
cursor.executeキーは文字列で、SQLテーブルの列には文字列がありません。この問題を解決する方法
Traceback (most recent call last):
File "pgrank.py", line 28, in <module>
cursor.execute("""update websites SET %s = %s where weblink = %s""",(key,value,x))
File "/usr/lib/python2.7/dist-packages/MySQLdb/cursors.py", line 174, in execute
self.errorhandler(self, exc, value)
File "/usr/lib/python2.7/dist-packages/MySQLdb/connections.py", line 36, in defaulterrorhandler
raise errorclass, errorvalue
_mysql_exceptions.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 '\'blog\'' = 1 where weblink = 'http://blogspot.com/' at line 1')