强制PHP在继续操作之前等待数据库操作完成 [英] Force PHP to wait for database action to complete before proceeding

查看:83
本文介绍了强制PHP在继续操作之前等待数据库操作完成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

给出一些这样的代码...

Given some code like this...

$rs = $dbh->prepare("insert some stuff into the database ?");
$rs->Execute(array($somevalues));
header("Location: http://somewebpage.com");
exit;

是否有一种方法可以强制PHP在处理代码的标头"部分之前等待数据库被更新?

Is there a way to force PHP to wait for the database to be updated before it processes the 'header' portion of the code?

我有一个更新数据的页面.我想返回到新"页面,以便用户可以刷新它,而浏览器不会提示重新提交数据.问题是,重定向和页面加载太快.它在上一个数据库操作完成之前从数据库加载数据,因此看起来更新没有发生在重新加载的页面上.我可以添加一个手动延迟,但这太粗糙了.我希望php代码只等数据库更新后再执行其他任何操作.

I have a page that updates data. I want to return to a 'fresh' page so that users can refresh it without the browser prompting to re-submit data. The problem is, the redirect and page load is too quick. It loads data from the database before the previous database operation has completed, so it looks like the update didn't happen on the reloaded page. I could add a manual delay but that's too crude. I want the php code to simply wait until the database is updated before it does anything else.

编辑-2011年12月4日:这似乎是一个简单的浏览器缓存问题.我已经在页面顶部添加了header("Cache-Control: no-cache, must-revalidate");,它现在可以按预期运行.

Edit - 04Dec11: It appears to have been a simple browser cacheing issue. I've added header("Cache-Control: no-cache, must-revalidate"); to the top of the page and it now works as expected.

推荐答案

也许只是浏览器缓存;)

Perhaps it's just browser cache ;)

这篇关于强制PHP在继续操作之前等待数据库操作完成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆