Home > Backend Development > PHP Tutorial > php实现同时发布,该如何解决

php实现同时发布,该如何解决

WBOY
Release: 2016-06-13 13:39:25
Original
924 people have browsed it

php实现同时发布
我想做一个表单提交功能 把提交的数据同时发布到3个数据库里 请问代码怎么实现呀?

------解决方案--------------------
这是我的笨办法
INSERT INTO TABLE1 (A,B,C) VALUES ($A,$B,$C)
INSERT INTO TABLE2 (A,B,C) VALUES ($A,$B,$C)
INSERT INTO TABLE3 (A,B,C) VALUES ($A,$B,$C)
------解决方案--------------------
有两个方案 1、如果这三个库是三个服务器的话 设置主从同步数据库即可 
2、如果是同一个数据库的三个库,不妨做个简单的内部接口,源程序不变 post数据到这个接口去 让这个接口完成数据库的插入工作!
------解决方案--------------------

SQL code

acquire mutex

con1: START TRANSACTION
con1: INSERT

con2: START TRANSACTION
con2: INSERT

con3: START TRANSACTION
con3: INSERT

flag = con1 insert ok && con2 insert ok && con3 insert ok

if ( flag ) {
  con1: COMMIT
  con2: COMMIT
  con3: COMMIT
} else {
  con1: ROLLBACK
  con2: ROLLBACK
  con3: ROLLBACK
}

release mutex <div class="clear">
                 
              
              
        
            </div>
Copy after login
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template