データを挿入する前にテーブルが存在するかどうかをチェックしたいと思います。 これは、私が試したものです:Pythonを使用してテーブルが存在するかどうかを確認するには?
def checkTables(tablename):
stmt = "SHOW TABLES LIKE %s"%tablename
cursor.execute(stmt)
result = cursor.fetchone()
return result
をしかし、それは言って私にエラーを与える:
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 'ctg_payload3' at line 1
パラメータの構文は正しいですか?例えば、どのデータベースを使用しているかに応じて、http://stackoverflow.com/questions/902408/how-to-use-variables-in-sql-statement-in-pythonたぶん 'cursor.execute("テーブルを表示する? "、(tablename))' – doctorlove