小编Jim*_*ith的帖子

Python MySQLdb执行表变量

我正在尝试将变量用于表名.我在第1行得到错误"......附近''myTable''我不能逃避这一点.错误中的双重'似乎是一个线索,但我不明白.

db = MySQLdb.connect("localhost","user","pw","database" )
table = "myTable"
def geno_order(db, table):
    cursor = db.cursor() # prepare a cursor object using cursor() method
    sql = "SELECT * FROM %s"
    cursor.execute(sql, table)
    results = cursor.fetchall()
Run Code Online (Sandbox Code Playgroud)

python mysql-python

12
推荐指数
1
解决办法
7004
查看次数

标签 统计

mysql-python ×1

python ×1