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

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

WBOY
WBOYOriginal
2016-06-13 10:14:30928browse

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 mutexcon1: START TRANSACTIONcon1: INSERTcon2: START TRANSACTIONcon2: INSERTcon3: START TRANSACTIONcon3: INSERTflag = con1 insert ok && con2 insert ok && con3 insert okif ( flag ) {  con1: COMMIT  con2: COMMIT  con3: COMMIT} else {  con1: ROLLBACK  con2: ROLLBACK  con3: ROLLBACK}release mutex<div class="clear">
                 
              
              
        
            </div>
Statement:
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