SQL_CALC_FOUND_ROWS / FOUND_ROWS() does not work in PHP

后端 未结 6 1422
情深已故
情深已故 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:08

    Are you using a MySQL query method that allows for multiple queries.

    From MySQL documentation.

    To obtain this row count, include a SQL_CALC_FOUND_ROWS option in the SELECT statement, and then invoke FOUND_ROWS() afterward

    Example:

    mysql> SELECT SQL_CALC_FOUND_ROWS * FROM tbl_name
        -> WHERE id > 100 LIMIT 10;
    mysql> SELECT FOUND_ROWS();
    

    Also just for fun, there's a great discussion about the race condition of FOUND_ROWS()'s usage here.

提交回复
热议问题