我想在插入數據之前檢查表是否存在。 這是我曾嘗試:如何使用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(「SHOW TABLES LIKE?」,(tablename))' – doctorlove