如何在python MySQLDB中执行SQL_CALC_FOUND_ROWS

时间:2010-03-08 10:06:51

标签: python mysql database select

cursor.execute("SELECT SQL_CALC_FOUND_ROWS user_id FROM...limit 5")
rows = cursor.fetchall()
...
total_rows = cursor.execute("SELECT FOUND_ROWS()") #this doesn't work for some reason.

编辑:我尝试了SELECT FOUND_ROWS()FROM my_table ......数字很时髦。

1 个答案:

答案 0 :(得分:1)

通过获取第二个游标的结果似乎在这里工作:

cursor.execute("SELECT SQL_CALC_FOUND_ROWS user_id FROM...limit 5")
rows = cursor.fetchall()

cursor.execute("SELECT FOUND_ROWS()")
(total_rows,) = cursor.fetchone()