doulangyu9636 2014-06-15 19:40
浏览 30
已采纳

使用PDO,有没有办法处理两个驱动程序之间的事务?

So, let's say I'm using two drivers at the same time (in the specific mysql and sqlite3)

I have a set of changes that must be commit()ted on both connections only if both dbms didn't fail, or rollBack()ed if one or the another did fail:

<?php

interface DBList
{
    function addPDO(PDO $connection);

    // calls ->rollBack() on all the pdo instances
    function rollBack();

    // calls ->commit() on all the pdo instances
    function commit();

    // calls ->beginTransaction() on all the pdo instances
    function beginTransaction();
}

Question is: will it actually work? Does it make sense?

"Why not use just mysql?" you would say! I'm not a masochist! I need mysql for the classic fruition via my application, but I also need to keep a copy of a table that is always synchronized and that is also downloadable and portable!

Thank you a lot in advance!

  • 写回答

2条回答 默认 最新

  • dtstnjl898781429 2014-06-15 19:51
    关注

    You mistake PDO with a database server. PDO is just an interface, pretty much like the database console. It doesn't perform any data operations of its own. It cannot insert or select data. It cannot perform data locks or transactions. All it can do is to send your command to database server and bring back results if any. It's just an interface. It doesn't have transactions on it's own.

    So, instead of such fictional trans-driver transactions you can use regular ones.

    Start two, one for each driver, and then rollback them accordingly. By the way, with PDO one don't have to rollback manually. Just set PDO in exception mode, write your queries and add commit at the end. In case one of queries failed, all started transactions will be rolled back automatically due to script termination.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器