SQL 适用于 php 我的管理员的代码语法错误

SQL Syntax error on code that worked on php my admin

我有以下在 phpmyadmin 中工作的代码:

CREATE TABLE IF NOT EXISTS Leaderboard2 (Player text, Score float)

当我运行在python中使用相同的代码(我希望能够更改排行榜):

make_leaderboard = ("CREATE TABLE IF NOT EXISTS Leaderboard%s (Player text, Score float)")
cursor.execute(make_leaderboard, *Leaderboard_Number*)

出现这个错误:

mysql.connector.errors.ProgrammingError: 1064 (42000): 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 '%s (Player text, Score float)' at line 1

关于如何解决这个问题有什么想法吗?

因为您在 table 名称上使用 %s,这将不起作用并在您的 sql 中创建错误,将变量添加为 table 名称使用 formatconcate 这样的字符串

make_leaderboard = "CREATE TABLE IF NOT EXISTS Leaderboard{num} (Player text, Score float)"
cursor.execute(make_leaderboard.format(num=Leaderboard_Number))

Parameter substitution('%s') in the python DB API is only for values - not tables or fields.