Symfony + Doctrine Oracle DateTime 格式问题 [英] Symfony + Doctrine Oracle DateTime format issue

查看:28
本文介绍了Symfony + Doctrine Oracle DateTime 格式问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Symfony 2.7 + Doctrine 中遇到了 Oracle DateTime 类型的问题.我有一个带有 DateTime 列的表,它通过 Doctrine 映射到 Symfony 中.

I have a problem with Oracle DateTime type in Symfony 2.7 + Doctrine. I have a table with a DateTime column which is mapped in Symfony through Doctrine.

当我尝试持久化相关实体时,出现以下错误:

When I try to persiste the relative Entity I got the following error:

无法将数据库值31-MAY-16 03.56.49.000000 PM"转换为 Doctrine Type 日期时间.预期格式:Y-m-d H:i:s 文件:.../vendor/doctrine/dbal/lib/Doctrine/DBAL/Types/ConversionException.php 行:63

Could not convert database value "31-MAY-16 03.56.49.000000 PM" to Doctrine Type datetime. Expected format: Y-m-d H:i:s File: .../vendor/doctrine/dbal/lib/Doctrine/DBAL/Types/ConversionException.php Line: 63

我无法更改 Oracle 数据库中的默认格式.我之前通过修改 vendor/doctrine/dbal/lib/Doctrine/DBAL/Platforms/OraclePlatform.php 中的方法 getDateTimeFormatString() 解决了这个问题,并且它起作用了.

I cannot change the default format in the Oracle Database. I previously fixed the problem by modifing the method getDateTimeFormatString() in the vendor/doctrine/dbal/lib/Doctrine/DBAL/Platforms/OraclePlatform.php and it worked.

但是,由于我必须使用 Git 和composer install ..."才能在生产环境中部署我的应用程序,因此所有供应商都从 Symfony 存储库安装;这样我就丢失了在 OraclePlatform.php

However, since I have to use Git and "composer install ..." in order to deploy my application in production environment, all vendors are installed from the Symfony repository; in that way I lose the changes I made in OraclePlatform.php

为了在不触及 verdors 库的情况下解决问题,我尝试在 httpd init 启动脚本上设置以下 Oracle ENV 变量,但它不起作用

To solve the problem without touching the verdors libraries, i tried to set the following Oracle ENV variables on httpd init start script but it doesn't work

导出 NLS_TIME_FORMAT="HH24:MI:SS"
export NLS_DATE_FORMAT="YYYY-MM-DD HH24:MI:SS"
export NLS_TIMESTAMP_FORMAT="YYYY-MM-DD HH24:MI:SS"
export NLS_TIMESTAMP_TZ_FORMAT="YYYY-MM-DD HH24:MI:SS TZH:TZM"

export NLS_TIME_FORMAT="HH24:MI:SS"
export NLS_DATE_FORMAT="YYYY-MM-DD HH24:MI:SS"
export NLS_TIMESTAMP_FORMAT="YYYY-MM-DD HH24:MI:SS"
export NLS_TIMESTAMP_TZ_FORMAT="YYYY-MM-DD HH24:MI:SS TZH:TZM"

我在 已知供应商问题 在有关 PostgreSQL 的 Doctrine 文档中,他们建议通过像这样覆盖类型来使用 VarDateTimeType:

use Doctrine\DBAL\Types\Type;

Type::overrideType('datetime', 'Doctrine\DBAL\Types\VarDateTimeType');
Type::overrideType('datetimetz', 'Doctrine\DBAL\Types\VarDateTimeType');
Type::overrideType('time', 'Doctrine\DBAL\Types\VarDateTimeType');

这似乎是解决方案,但是我不知道如何使用上面的代码覆盖类型,但主要是将上面的代码放在哪里.

This seams to be the solution, however I have no idea on how to override the type with the code above but mostly where to put the above code.

有人知道吗?谢谢

附言我正在使用没有时区的 DateTime

P.S. I'm using DateTime without timezone

推荐答案

我根据 Github 中的此评论.在 app/config/config.yml (Symfony 2.3.1) 中,我添加了以下块:

I fixed the problem following the proposal of this comment in Github. In app/config/config.yml (Symfony 2.3.1) I added the following block:

services:
    oracle.listener:
        class: Doctrine\DBAL\Event\Listeners\OracleSessionInit
        tags:
            - { name: doctrine.event_listener, event: postConnect }

这篇关于Symfony + Doctrine Oracle DateTime 格式问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆