【问题标题】:How do I execute SQL_CALC_FOUND_ROWS in python MySQLDB如何在 python MySQLDB 中执行 SQL_CALC_FOUND_ROWS
【发布时间】:2011-01-24 22:08:37
【问题描述】:
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...而且数字很时髦。

【问题讨论】:

  • 谢谢顺便说一句。我不知道SQL_CALC_FOUND_ROWS / SELECT FOUND_ROWS() :D

标签: python mysql database select


【解决方案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()

【讨论】:

    猜你喜欢
    • 2010-11-01
    • 1970-01-01
    • 1970-01-01
    • 2012-05-22
    • 2012-06-08
    • 1970-01-01
    • 2011-05-23
    • 2013-02-21
    • 1970-01-01
    相关资源
    最近更新 更多