1. <tfoot id='5iXhN'></tfoot>
        <i id='5iXhN'><tr id='5iXhN'><dt id='5iXhN'><q id='5iXhN'><span id='5iXhN'><b id='5iXhN'><form id='5iXhN'><ins id='5iXhN'></ins><ul id='5iXhN'></ul><sub id='5iXhN'></sub></form><legend id='5iXhN'></legend><bdo id='5iXhN'><pre id='5iXhN'><center id='5iXhN'></center></pre></bdo></b><th id='5iXhN'></th></span></q></dt></tr></i><div id='5iXhN'><tfoot id='5iXhN'></tfoot><dl id='5iXhN'><fieldset id='5iXhN'></fieldset></dl></div>
        <legend id='5iXhN'><style id='5iXhN'><dir id='5iXhN'><q id='5iXhN'></q></dir></style></legend>
          <bdo id='5iXhN'></bdo><ul id='5iXhN'></ul>
      1. <small id='5iXhN'></small><noframes id='5iXhN'>

        PDO、mysql、事务和表锁定

        PDO, mysql, transactions and table locking(PDO、mysql、事务和表锁定)
          <bdo id='Dn5WN'></bdo><ul id='Dn5WN'></ul>
        • <tfoot id='Dn5WN'></tfoot>
          <i id='Dn5WN'><tr id='Dn5WN'><dt id='Dn5WN'><q id='Dn5WN'><span id='Dn5WN'><b id='Dn5WN'><form id='Dn5WN'><ins id='Dn5WN'></ins><ul id='Dn5WN'></ul><sub id='Dn5WN'></sub></form><legend id='Dn5WN'></legend><bdo id='Dn5WN'><pre id='Dn5WN'><center id='Dn5WN'></center></pre></bdo></b><th id='Dn5WN'></th></span></q></dt></tr></i><div id='Dn5WN'><tfoot id='Dn5WN'></tfoot><dl id='Dn5WN'><fieldset id='Dn5WN'></fieldset></dl></div>
            <tbody id='Dn5WN'></tbody>

          • <small id='Dn5WN'></small><noframes id='Dn5WN'>

                1. <legend id='Dn5WN'><style id='Dn5WN'><dir id='Dn5WN'><q id='Dn5WN'></q></dir></style></legend>

                2. 本文介绍了PDO、mysql、事务和表锁定的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  为了好玩,我将应用程序中的 mysqli 扩展替换为 PDO.

                  For fun I am replacing the mysqli extension in my app with PDO.

                  偶尔我需要使用事务 + 表锁定.

                  Once in awhile I need to use transactions + table locking.

                  在这些情况下,根据mysql手册,语法需要有点不同.与其调用 START TRANSACTION,不如这样做...

                  In these situations, according to the mysql manual, the syntax needs to be a bit different. Instead of calling START TRANSACTION, you do it like so...

                  SET autocommit=0;
                  LOCK TABLES t1 WRITE, t2 READ, ...;
                  ... do something with tables t1 and t2 here ...
                  COMMIT;
                  UNLOCK TABLES;
                  

                  (http://dev.mysql.com/doc/refman/5.0/en/lock-tables-and-transactions.html)

                  我的问题是,这如何与 PDO::beginTransaction 交互?在这种情况下,我可以使用 PDO::beginTransaction 吗?或者我应该手动发送sqlSET autocommit = 0; ... etc".

                  My question is, how does this interact with PDO::beginTransaction? Can I use PDO::beginTransaction in this case? Or should I manually send the sql "SET autocommit = 0; ... etc".

                  谢谢你的建议,

                  推荐答案

                  在 MySQL 中,由于 LOCK/UNLOCK TABLES 的工作方式,开始事务与关闭自动提交不同.在 MySQL 中,LOCK TABLES 提交任何打开的事务,但关闭自动提交实际上并不是启动事务.MySQL 在这方面很有趣.

                  In MySQL, beginning a transaction is different than turning off autocommit, due to how LOCK/UNLOCK TABLES works. In MySQL, LOCK TABLES commits any open transactions, but turning off autocommit isn't actually starting a transaction. MySQL is funny that way.

                  在 PDO 中,使用 beginTransaction 启动事务实际上并未启动一个新的事务,它只是关闭自动提交.在大多数数据库中,这是合理的,但它可能会对 MySQL 提到的行为产生副作用.

                  In PDO, starting a transaction using beginTransaction doesn't actually start a new transaction, it just turns off autocommit. In most databases, this is sane, but it can have side effects with MySQL's mentioned behavior.

                  您可能不应该依赖这种行为以及它如何与 MySQL 的怪癖进行交互.如果您要处理 MySQL 的表锁定和 DDL 行为,您应该避免它.如果您想关闭自动提交,请手动将其关闭.如果要开启交易,请手动开启交易.

                  You probably should not rely on this behavior and how it interacts with MySQL's quirks. If you're going to deal with MySQL's behavior for table locking and DDL, you should avoid it. If you want autocommit off, turn it off by hand. If you want to open a transaction, open a transaction by hand.

                  您可以自由地混合使用 PDO API 方法来处理事务和 SQL 命令,而无需以其他方式处理 MySQL 的奇怪问题.

                  You can freely mix the PDO API methods of working with transactions and SQL commands when not otherwise working with MySQL's oddities.

                  这篇关于PDO、mysql、事务和表锁定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  DeepL的翻译效果还是很强大的,如果我们要用php实现DeepL翻译调用,该怎么办呢?以下是代码示例,希望能够帮到需要的朋友。 在这里需要注意,这个DeepL的账户和api申请比较难,不支持中国大陆申请,需要拥有香港或者海外信用卡才行,没账号的话,目前某宝可以
                  PHP通过phpspreadsheet导入Excel日期,导入系统后,全部变为了4开头的几位数字,这是为什么呢?原因很简单,将Excel的时间设置问文本,我们就能看到该日期本来的数值,上图对应的数值为: 要怎么解决呢?进行数据转换就行,这里可以封装方法,或者用第三方的
                  mediatemple - can#39;t send email using codeigniter(mediatemple - 无法使用 codeigniter 发送电子邮件)
                  Laravel Gmail Configuration Error(Laravel Gmail 配置错误)
                  Problem with using PHPMailer for SMTP(将 PHPMailer 用于 SMTP 的问题)
                  Issue on how to setup SMTP using PHPMailer in GoDaddy server(关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题)
                    <tfoot id='ylbNA'></tfoot>
                  1. <legend id='ylbNA'><style id='ylbNA'><dir id='ylbNA'><q id='ylbNA'></q></dir></style></legend>

                      <tbody id='ylbNA'></tbody>
                    • <small id='ylbNA'></small><noframes id='ylbNA'>

                      • <bdo id='ylbNA'></bdo><ul id='ylbNA'></ul>

                            <i id='ylbNA'><tr id='ylbNA'><dt id='ylbNA'><q id='ylbNA'><span id='ylbNA'><b id='ylbNA'><form id='ylbNA'><ins id='ylbNA'></ins><ul id='ylbNA'></ul><sub id='ylbNA'></sub></form><legend id='ylbNA'></legend><bdo id='ylbNA'><pre id='ylbNA'><center id='ylbNA'></center></pre></bdo></b><th id='ylbNA'></th></span></q></dt></tr></i><div id='ylbNA'><tfoot id='ylbNA'></tfoot><dl id='ylbNA'><fieldset id='ylbNA'></fieldset></dl></div>