跨多个数据库进行PDO交易,这可能吗?

问题描述:

我的一位用户遇到以下问题:他们在两个不同的位置都有两家商店,每个地方都有自己的数据库,但是,他们需要共享客户群和注册出售的物料清单.目前,我们要做的是当客户注册一个新客户时,在另一个位置的数据库上创建一个副本.由于互联网连接不稳定,因此问题很快出现.如果在注册时互联网中断,它将尝试进行复制,失败并携带不一致的数据库.

I have the following problem with one of our users: they have two stores in two diferent locations, each place has its own database, however, they need to share the client base and the list of materials registered for sale. At the moment, what we do is when the client registers a new client, a copy is made on the other location's database. Problems quickly arise as their internet connection is unstable. If, at the time of the registration, the internet is down, it tries to make a copy, fails and carries with inconsistent databases.

我考虑过通过管理两个数据库的Pdo事务对数据库进行更新,但是似乎每个数据库都需要一个新的PDO $dbh1= new PDO('mysql:host=xxxx;dbname=test',$user,$pass);实例,但是我看不到同时提交这两个方法的方法更新.看着这个相关问题什么是在多个数据库中进行分布式事务的最佳方法,看来我需要一些用于事务管理的方法. PDO可以实现吗?

I considered making the updates to the database via Pdo transactions that would manage the two databases, but it seems that you need a new instance of PDO $dbh1= new PDO('mysql:host=xxxx;dbname=test',$user,$pass); for each database, and I don't see a way to commit both updates. Looking at this related question what is the best way to do distributed transactions across multiple databases it seems that I need some for transation management. Can this be achieved by PDO?

不,PDO无法做任何与分布式事务类似的事情(无论如何,这是一个非常棘手的问题,没有灵丹妙药.)

No, PDO cannot do anything remotely resembling distributed transactions (which in any case are a very thorny issue where no silver bullets exist).

通常,在存在网络分区(即参与者从网络上掉下来)的情况下,可以证明:您无法同时实现一致性和可用性(对查询的保证响应)- -请参见 CAP定理.

In general, in the presence of network partitions (i.e. actors falling off the network) it can be proved that you cannot achieve consistency and availability (guaranteed response to your queries) at the same time -- see CAP theorem.

您似乎需要重新评估您的需求,并根据此分析结果设计解决方案;为了横向扩展数据处理或存储,您必须从第一天开始就考虑扩展,并做出相应计划.

It seems that you need to re-evaluate your requirements and design a solution based on the results of this analysis; in order to scale data processing or storage horizontally you have to take the scaling into account from day one and plan accordingly.