我几乎肯定我的查询正在被缓存。这是一个SELECT语句。PDO/MySQL/PHP - 问题与我的查询结果被缓存
以下是一个示例情况。目前有2个挂单。我有一个脚本,在主页上显示挂单通知,通知仓库是否有新订单。我下了一个命令来测试“2”是否更新为“3”,但没有。我想我的查询被缓存,因为当我从phpMyAdmin运行查询时,它显示“3”,但是当通过PHP运行时,它只显示“2”。任何想法如何解决这个问题或禁用特定查询的缓存?
这里是我的原代码
<?php
if(protectThis("1, 2")) :
$pending = $conn->query("SELECT count(*) FROM orders WHERE `status` =0");
$pending2 = $pending->fetch();
$pendingcount = count($pending2);
if ($pendingcount > 0) {
?>
<div class="orange warning">
<p>
<strong>Pending Order Notification</strong>
<br />There are currently <strong><?php echo $pendingcount; ?></strong> pending orders.
<br /><a style="color:white;margin-top:10px;" class="btn btn-inverse" href="orders_pending.php"><i>Click here to view them.</i></a>
</p>
<div class="shadow-out"></div>
</div>
<?php
}
endif;
我试着想禁用特定的查询缓存读了之后改变了查询,并尝试了以下
SELECT SQL_NO_CACHE count(*) FROM orders WHERE `status` =0
显然没有奏效无论是。
我不知道该怎么做。 :\
任何帮助,非常感谢。
“编辑1”
$pending = $conn->query("SELECT count(*) FROM orders WHERE `status` =0");
// $pending2 = $pending->fetch();
// $pendingcount = count($pending2);
$pendingcount = $pending->rowCount();
if ($pendingcount > 0) {
太棒了。这工作。现在,有什么办法可以设置特定的查询不被缓存?因为我有另一个页面显示注册用户列表,并且我添加了一个用户,直到1-2小时后他才从列表中出现,并且无数页面刷新。 –
['SQL_NO_CACHE'](http://dev.mysql.com/doc/refman/5.0/en/query-cache-in-select.html)应该像你使用的那样工作。如果您仍然看到过时的数据,则可能是其他情况。也许一些PHP框架,或者你的浏览器? – bfavaretto
由于某种原因,var_dump是一个字符串,而不是整数 –