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

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

        Doctrine 不会在 Mysql 中使用布尔值和 PDO::ATTR_EMULATE_PREPARES = fals

        Doctrine doesn#39;t persist entity with boolean values and PDO::ATTR_EMULATE_PREPARES = false in Mysql(Doctrine 不会在 Mysql 中使用布尔值和 PDO::ATTR_EMULATE_PREPARES = false 持久化实体)

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

              <legend id='QYZhV'><style id='QYZhV'><dir id='QYZhV'><q id='QYZhV'></q></dir></style></legend>

              1. <small id='QYZhV'></small><noframes id='QYZhV'>

                <tfoot id='QYZhV'></tfoot>

                • <bdo id='QYZhV'></bdo><ul id='QYZhV'></ul>
                  本文介绍了Doctrine 不会在 Mysql 中使用布尔值和 PDO::ATTR_EMULATE_PREPARES = false 持久化实体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我们正在使用 Symfony 创建一些网络服务.我们使用 Doctrine-ORM 来存储实体,使用 Doctrine-DBAL 来检索数据,因为它非常轻便,并且可以重用 ORM(实体管理器)连接.

                  We are using Symfony to create some webservices. We use Doctrine-ORM to store entities and Doctrine-DBAL to retrive data because it's very light and can reuse the ORM (entity manager) connection.

                  当使用 Doctrine-DBAL 时,整数值作为字符串返回给 PHP,我们希望有整数值,特别是因为它们返回到 Javascript.在此讨论之后 如何从 MySQL 获取数字类型使用 PDO? 我们已经安装了 mysql 本机驱动程序 sudo apt-get install php5-mysqlnd 并使用 PDO::ATTR_EMULATE_PREPARE = false 设置了我们的 symfony (dbal) 配置:

                  When using Doctrine-DBAL, integer values are returned to PHP as strings and we want to have integer values, specially because they are retured to Javascript. Following this discussion How to get numeric types from MySQL using PDO? we have installed mysql native driver sudo apt-get install php5-mysqlnd and setup our symfony (dbal) configuration with PDO::ATTR_EMULATE_PREPARE = false :

                  doctrine:
                      dbal:
                           .
                           .
                  
                           options:
                              20 : false # PDO::ATTR_EMULATE_PREPARES is 20
                  

                  使用此配置,当 mysql 字段为整数时,我们将获得整数.到目前为止一切顺利.

                  With this configuration we are getting integers when mysql fields are integers. So far so good.

                  但是有一个新问题:当通过 Doctrine-ORM 存储具有布尔值的实体时,实体不会被持久化.我们在日志中看到了 INSERT 和 COMMIT,但该记录不在数据库中(如果我们使用没有在实体中定义布尔字段的表,则会存储该记录).

                  But there is a new problem: When storing entities with boolean values through Doctrine-ORM the entity is not persisted. We see in the logs the INSERT and the COMMIT, but the record is not in the database (if we use a table with no boolean fields defined in the entity, the record is stored).

                  此外,我们没有收到任何错误或异常,因此我们发现这非常危险.我们认为 PDO 库中存在错误,但我们必须对其进行更多研究.

                  Furthermore, we don't get any Error or Exception, so we find this very dangerous. We think there is a bug in the PDO library but we have to look a bit more into it.

                  问题:有人遇到过这种行为吗?任何解决方法?Doctrine 应该对此负责吗?

                  The question: Has anybody experienced this behaviour? any workaround? Should Doctrine account for this?

                  推荐答案

                  gseric 的 answer 将起作用,但与用整数滋润你的实体的效果.为了仍然在你的实体中获得布尔值,你可以简单地扩展 Doctrine 的 BooleanType:

                  gseric's answer will work but with the effect of hydrating your entities with integers. To still get booleans in your entities you can simply extend Doctrine's BooleanType:

                  class BooleanToIntType extends DoctrineDBALTypesBooleanType
                  {
                      public function getBindingType()
                      {
                          return PDO::PARAM_INT;
                      }
                  }
                  

                  然后,在您的应用程序引导程序中:

                  Then, in your application bootstrap:

                  DoctrineDBALTypesType::overrideType('boolean', BooleanToIntType::class);
                  

                  这篇关于Doctrine 不会在 Mysql 中使用布尔值和 PDO::ATTR_EMULATE_PREPARES = false 持久化实体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  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 的问题)
                    <legend id='crflq'><style id='crflq'><dir id='crflq'><q id='crflq'></q></dir></style></legend>
                    <tfoot id='crflq'></tfoot>

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

                          <bdo id='crflq'></bdo><ul id='crflq'></ul>
                        • <small id='crflq'></small><noframes id='crflq'>