如何在python中打印计数表sql

时间:2014-02-02 12:29:08

标签: python sql mysql-python

我试图在python中打印计数表,我写这段代码:

count = cur.execute("SELECT COUNT(*) FROM %s;" str(table))
print count

所有打印结果都是1,(想想1 =真),我怎样才能打印出我的sql命令的真实结果?

感谢

1 个答案:

答案 0 :(得分:3)

您必须获取结果:

cursor = db.cursor()
count = cursor.execute("SELECT COUNT(*) FROM " + str(table))
db.commit()
print cursor.fetchone()[0]
cursor.close()