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

      <bdo id='EyfiG'></bdo><ul id='EyfiG'></ul>

      1. <tfoot id='EyfiG'></tfoot>
      2. <legend id='EyfiG'><style id='EyfiG'><dir id='EyfiG'><q id='EyfiG'></q></dir></style></legend>

        原则 2:无法更新 SQL Server 2008apm 上的 DateTime 列

        时间:2024-08-15

      3. <legend id='shZXe'><style id='shZXe'><dir id='shZXe'><q id='shZXe'></q></dir></style></legend>

          <tbody id='shZXe'></tbody>
          <bdo id='shZXe'></bdo><ul id='shZXe'></ul>

          <small id='shZXe'></small><noframes id='shZXe'>

            • <i id='shZXe'><tr id='shZXe'><dt id='shZXe'><q id='shZXe'><span id='shZXe'><b id='shZXe'><form id='shZXe'><ins id='shZXe'></ins><ul id='shZXe'></ul><sub id='shZXe'></sub></form><legend id='shZXe'></legend><bdo id='shZXe'><pre id='shZXe'><center id='shZXe'></center></pre></bdo></b><th id='shZXe'></th></span></q></dt></tr></i><div id='shZXe'><tfoot id='shZXe'></tfoot><dl id='shZXe'><fieldset id='shZXe'></fieldset></dl></div>
              <tfoot id='shZXe'></tfoot>
                1. 本文介绍了原则 2:无法更新 SQL Server 2008apm 上的 DateTime 列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我在 apache 服务器上使用 Doctrine 2.2 和 php 5.3.

                  I'm using Doctrine 2.2 with php 5.3 on an apache server.

                  到目前为止,我偶然发现了以下问题:当我尝试更新日期时间列时,我得到:SQLSTATE[22007]:[Microsoft][SQL Server Native Client 10.0][SQL Server]从字符串转换日期和/或时间时转换失败.

                  So far I've stumbled upon the following problem: When I try to update a datetime column I get: SQLSTATE[22007]: [Microsoft][SQL Server Native Client 10.0][SQL Server]Conversion failed when converting date and/or time from character string.

                  到目前为止,我什至已经进入该列,然后使用它只添加了 1 天来设置新日期......同样的结果.

                  I've even gone so far to make a get onto the column and then use that with only 1 day added to it to set the new date......same result.

                  当我将数据库中的列和实体中的列从日期时间更改为日期时,它按预期运行.

                  When I instead change both the column in the database and in the entity from datetime to date, it functions as intended.

                  我的主要问题是,有几个字段我需要使用日期时间列.

                  My main problem is, that there are a few fields where I will NEED to use a datetime column.

                  这是我的代码:

                  (birthdate 是我更改为 date 的栏目......并且是为数不多的对我来说可能的栏目之一):

                  (birthdate was the column I changed to date....and is one of the few columns where that is possible for me):

                  //This returns the datetime object that represents birthdate from the database 
                  $help=$object->getBirthDate(); 
                  $help->setTimestamp(mktime($time[0],$time[1],$time[2],$date[2],$date[1],$date[0])); 
                  $help->format(DateTime::ISO8601); 
                  $object->setBirthDate($help);
                  

                  有人知道这里的解决方法吗?

                  Does someone know a workaround here?

                  推荐答案

                  我在使用 Doctrine 2.5 和 SQL Server 2012 时遇到了这个问题.问题是数据库字段类型为 DATETIME,但是 doctirne仅在 SQLServer2008Platform 及更高版本上支持 DATETIME2.

                  I ran into this problem with Doctrine 2.5 and SQL Server 2012. The problem is that the database field is type DATETIME, but doctirne only supports DATETIME2 on SQLServer2008Platform and up.

                  您不应该在您的供应商目录中编辑文件.正确的答案是创建一个自定义类型:Doctrine 自定义映射类型.就我而言,我扩展了当前的 DateTimeType:

                  You should not be editing files in your vendor directory. The correct answer is to create a custom type: Doctrine Custom Mapping Types. In my case, I extended the current DateTimeType:

                  <?php
                  
                  namespace AppBundleDoctrineType;
                  
                  use DoctrineDBALTypesDateTimeType;
                  use DoctrineDBALPlatformsAbstractPlatform;
                  
                  class DateTime extends DateTimeType
                  {
                      private $dateTimeFormatString = 'Y-m-d H:i:s.000';
                  
                      public function convertToDatabaseValue($value, AbstractPlatform $platform)
                      {
                          return ($value !== null)
                              ? $value->format($this->dateTimeFormatString) : null;
                      }
                  
                  }
                  

                  然后在 Symfony config.yml 中:

                  And then in the Symfony config.yml:

                      types:
                        datetime: AppBundleDoctrineTypeDateTime
                  

                  这篇关于原则 2:无法更新 SQL Server 2008apm 上的 DateTime 列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:Doctrine 中的分离实体错误 下一篇:如何在 Doctrine 2 中为 1:1 关系指定多个连接条件

                  相关文章

                  <small id='13Zc7'></small><noframes id='13Zc7'>

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

                  1. <tfoot id='13Zc7'></tfoot>
                      <legend id='13Zc7'><style id='13Zc7'><dir id='13Zc7'><q id='13Zc7'></q></dir></style></legend>

                        <bdo id='13Zc7'></bdo><ul id='13Zc7'></ul>