如何在PHP中使用mysql表的并发访问 [英] How can I use concurrent access of mysql table in PHP

查看:104
本文介绍了如何在PHP中使用mysql表的并发访问的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个Php文件(a.php,b.php)。在a.php中,我从表中检索一个值,并在PHP中显示该值,并将其发送到b.php。在b.php中,我将该值增加1并在表上进行了更新(但是b.php由于需要进行许多操作,因此会花费更多时间)。现在的问题是在b.php中执行操作时,如果我单击a.php来执行另一任务,则需要获取递增的值以在a.php中显示,但是由于b,它仅显示先前的值。 php没有完全执行。帮我解决这个问题。

I have two Php files (a.php, b.php). In a.php I'm retrieving a value from a table and displaying it in PHP and sending it to b.php. In b.php, I'm incrementing that value by 1 and updating it on the table, (but b.php will take more time because of many operations). Now the problem is when performing the operation in b.php, if I clicked a.php for another task, I need to get the incremented value to display in a.php, but it will show only the previous value, because the b.php is not fully executed. Help me to solve this issue.

推荐答案

一个 INSERT UPDATE DELETE 操作将锁定相关表[myISAM]或行[InnoDB],直到操作完成。如果 SELECT 试图读取锁定的对象,它将等待操作完成。

An INSERT, UPDATE, or DELETE operation locks the relevant tables [myISAM] or rows [InnoDB] until the operation completes. If a SELECT comes in trying to read a locked object it will wait for the operation to complete.

值得请注意,除非您的服务器严重过载,或者您的 INSERT / UPDATE / DELETE 操作数在数千行中,或者在两行中都没有,您甚至都不会注意到等待。

It's worth noting that unless your server is horrendously overloaded, or your INSERT/UPDATE/DELETE operations number in the many thousands of rows, or both, you will not even notice the wait.

简而言之:您甚至不必担心担心你所说的。

In short: don't even bother worrying about what you've described.

这篇关于如何在PHP中使用mysql表的并发访问的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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