SQL_CALC_FOUND_ROWS / FOUND_ROWS() does not work in PHP

后端 未结 6 1421
情深已故
情深已故 2020-12-01 14:08

I use SQL_CALC_FOUND_ROWS in Mysql SELECT statement, to get the number of lines my SELECT would return without a LIMIT clause.

$sql = new mysqli         


        
6条回答
  •  情深已故
    2020-12-01 15:03

    The quickest solution is to subquery your actual query like this:

    SELECT SQL_CALC_FOUND_ROWS * FROM (SELECT whatever FROM whatever WHERE whatever LIMIT whatever) ax; 
    select FOUND_ROWS();
    

    Now you will get the correct results. I think the main reason being that SQL_CALC_FOUND_ROWS mainly tracks rows found (i.e. without LIMITS) not rows returned.

提交回复
热议问题