多个数据库用户同时更新 [英] Multiple DB users updating at the same time

查看:138
本文介绍了多个数据库用户同时更新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很好奇我应该采取什么路径来完成以下任务.我希望一台计算机上的多台计算机能够使用Web浏览器查看和更改mysql DB中的数据.我在这方面没有广泛的知识,但是据我所记得,这非常困难,即使不是不可能.

I am curious what path I should take to accomplish the following. I want multiple computers at one location to be able to view and make changes to data inside a mysql DB with a web browser. I dont have extensive knowledge in this area, but from what I do remember this was very difficult if not impossible.

示例:假设我有一个John记录,并且我希望2台计算机能够编辑Johns记录.请注意,计算机将不会编辑Johns记录的相同部分.可以说,一条记录将状态从需要调用更改为调用,另一台计算机将需要订购的状态更改为已订购.

Example: Lets say I have a record for John and I want 2 computers to be able to edit Johns record. Please note that the computers will not be editing the same portion of Johns record. Lets say one record is changing a status from need to be called to called and the other computer is changing the status of need to be ordered to ordered.

我想要一个可以本地处理的解决方案.

I want a solution that could natively handle this.

我目前的知识是使用PHP和SQL构建Web界面.我想使用这些语言,因为我已经掌握了一些知识.

My current knowledge is building web interfaces with PHP and SQL. I would like to use these languages as I have some prior knowledge.

所以我的问题是:这可能吗?如果可以,那么它将如何工作(信息流)?

So my question: Is this possible? If, so exactly how would it work(flow of info)?

推荐答案

有几种方法可以实现此目的.已经有一些很棒的PHP数据库编辑软件包(phpMyAdmin).

There are several ways that you can accomplish this. There's already some great PHP database editing software packages out there (phpMyAdmin).

要在代码中处理此问题,尽管您可以使用事务处理(取决于您使用的SQL风格,这会有所不同)

To handle this in code though you can either use Transactions (depending on what flavor of SQL you're using this would be done differently)

一种简单的方法来确保您的数据不会相互冲突,只需在语句中添加其他where子句即可.

One of the easier ways to ensure that you don't have people's data clashing with one another is just by adding additional where clauses to your statement.

假设您有一条用户记录,并且要将姓氏从Smith更改为Bill,并且用户ID为4.

Lets say you have a user record and you want to update the last name from Smith to Bill, and the user ID is 4.

代替写作

   UPDATE users SET lastName='Bill' WHERE id='4'

您将添加:

   UPDATE users SET lastName='Bill' WHERE id='4' AND lastName='Smith'

这样,如果其他人在您处理姓氏字段时对其进行更新,则查询将失败,并且您将不得不重新输入数据,从而伪造交易

That way if someone else updates the last name field while you're working on it, your query will fail and you'll have to re-enter the data, thus faking a transaction

这篇关于多个数据库用户同时更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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