FOUND_ROWS() keeps returning 0(FOUND_ROWS() 不断返回 0)
问题描述
$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 = $count_result->fetch_assoc();
$total = $row['totalcount'];
即使 $result 包含其中的所有用户行,$total 仍然返回 0.
$total keeps returning 0 even though the $result contains all the user rows in it.
ini_set("mysql.trace_mode", "0");
我通过在此处搜索类似的 Q 发现了此设置,但它没有解决我的问题.
I found out about this setting via searching a similar Q on here, but it did not resolve my issue.
当我在 MySQL 客户端中使用 2 个 select 语句时,它总是输出正确的计数.只是似乎无法弄清楚如何让它在我的 php 页面上工作.
When I use the 2 select statements in my MySQL client it always outputs the right count. Just can't seem to figure out how to get it working on my php page.
PHP 版本:5.2.5 构建 6MySQL 版本:5.1.30
PHP Version: 5.2.5 build 6 MySQL Version: 5.1.30
注意:我在此处提供的代码并未在我的实际项目中使用,但是,它确实体现了我无法检索总数的问题.这段代码,从我读过的关于 found_rows() 的内容来看,应该可以工作,但没有.
Note: The code I provided here is not being used on my actual project, however, it does exemplify the problem I am having with not being able to retrieve the total count. This code, from what I've read about found_rows(), should work but it doesn't.
推荐答案
在 php.net 上,我发现有人可能遇到了同样的问题.他说的是可能发生的竞争条件:php.net.基本上他通过以减慢速度为代价临时锁定表来解决这个问题.
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.
这篇关于FOUND_ROWS() 不断返回 0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:FOUND_ROWS() 不断返回 0


- 使用 GD 和 libjpeg 支持编译 PHP 2022-01-01
- 如何使用 Google API 在团队云端硬盘中创建文件夹? 2022-01-01
- 覆盖 Magento 社区模块控制器的问题 2022-01-01
- PHP foreach() 与数组中的数组? 2022-01-01
- Laravel 5:Model.php 中的 MassAssignmentException 2021-01-01
- Oracle 即时客户端 DYLD_LIBRARY_PATH 错误 2022-01-01
- openssl_digest vs hash vs hash_hmac?盐与盐的区别HMAC? 2022-01-01
- 如何在 Symfony2 中正确使用 webSockets 2021-01-01
- 如何从数据库中获取数据以在 laravel 中查看页面? 2022-01-01
- PHP - if 语句中的倒序 2021-01-01