FOUND_ROWS() keeps returning 0

前端 未结 3 690
鱼传尺愫
鱼传尺愫 2021-01-06 17:41
$result = $db_con->query(\"SELECT SQL_CALC_FOUND_ROWS * FROM users LIMIT 0,10\");

$count_result = $db_con->query(\"SELECT FOUND_ROWS() as totalcount\");
$row          


        
相关标签:
3条回答
  • 2021-01-06 18:11

    LIMIT is required to make found_rows() work correctly

    Add a LIMIT to the end of your query, ie.

    SELECT SQL_CALC_FOUND_ROWS * FROM users LIMIT 0,10;
    

    http://dev.mysql.com/doc/refman/5.0/en/information-functions.html#function_found-rows

    FOUND_ROWS() -- For a SELECT with a LIMIT clause, the number of rows that would be returned were there no LIMIT clause

    0 讨论(0)
  • 2021-01-06 18:12

    On php.net I found someone with maybe the same problem. He is speaking of a race condition that could occur: php.net. Basically he solves this problem by temporary locking the table at the cost of slowing things down.

    0 讨论(0)
  • 2021-01-06 18:26

    I'm not sure what database library you're using but it looks like you are trying to count the number of rows in a select statement in php from a mysql database.

    Have you tried seeing if it works with the built in mysql database functions in php?

    $count_result = mysql_query("SELECT COUNT(*) as totalcount FROM users");
    $row = mysql_fetch_array($count_result);
    
    $total = $row['totalcount'];
    
    0 讨论(0)
提交回复
热议问题