如何在Symfony2中使用Doctrine OracleSessionInit监听器?

时间:2022-09-15 20:12:53

I am using oracle and I am recieving this error:

我正在使用oracle,我收到了这个错误:

Could not convert database value "17-NOV-11 12.17.33 AM" to Doctrine Type datetime. Expected format: Y-m-d H:i:s

无法将数据库值“17-NOV-11 12.17.33 AM”转换为Doctrine Type datetime。预期格式:Y-m-d H:i:s

Also I can´t create new rows because oracle complaints about the datetime format.

此外,我无法创建新行,因为oracle抱怨日期时间格式。

I know that mysql datetime format and oracle one are different.

我知道mysql的datetime格式和oracle的格式不同。

I understand that you can use doctrine listeners with symfony 2:

我知道你可以使用symfony 2的教义听众:

http://symfony.com/doc/current/cookbook/doctrine/event_listeners_subscribers.html

http://symfony.com/doc/current/cookbook/doctrine/event_listeners_subscribers.html

And, there´s a doctrine listener created to fix this issue:

并且,有一个学说监听器来解决这个问题:

Doctrine/DBAL/Event/Listeners/OracleSessionInit.php

学说/ DBAL /事件/监听器/ OracleSessionInit.php

The question is how Exactly your turn it on in symfony 2.

问题是如何在symfony 2中完全启用它。

3 个解决方案

#1


16  

Well It appears I will answer myself this time.

好吧看来我这次会回答自己。

You have to add it as a service using the event tag.

您必须使用事件标记将其添加为服务。

app/config/config.yml 

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

my.listener is an arbitrary name for the listener.

my.listener是侦听器的任意名称。

#2


8  

In my case Oracle was a second connection (stored under oracle key). The application also used PostgreSQL (stored under default key).

在我看来,Oracle是第二个连接(存储在oracle密钥下)。该应用程序还使用PostgreSQL(存储在默认密钥下)。

The problem was that Listener was executed on the default database (PostgreSQL). So I changed code to:

问题是Listener是在默认数据库(PostgreSQL)上执行的。所以我将代码更改为:

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

And all works fine!

一切正常!

#3


-2  

I think this link will help you :

我认为此链接可以帮助您:

Connecting to Oracle with Symfony2 and Doctrine 2.

使用Symfony2和Doctrine 2连接到Oracle。

  1. Map Oracle's DATE type to Doctrine's "date" type instead of "datetime" for Oracle driver
  2. 将Oracle的DATE类型映射到Doctrine的“日期”类型,而不是Oracle驱动程序的“datetime”
  3. Properly configures Doctrine to use most common Oracle Date and DateTime environment configurations. You may or may not need this. Check your Oracle server configuration
  4. 正确配置Doctrine以使用最常见的Oracle Date和DateTime环境配置。您可能需要也可能不需要此功能。检查Oracle服务器配置

https://gist.github.com/johnkary/6481664#file-oracledoctrinetypemappinglistener-php

https://gist.github.com/johnkary/6481664#file-oracledoctrinetypemappinglistener-php

#1


16  

Well It appears I will answer myself this time.

好吧看来我这次会回答自己。

You have to add it as a service using the event tag.

您必须使用事件标记将其添加为服务。

app/config/config.yml 

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

my.listener is an arbitrary name for the listener.

my.listener是侦听器的任意名称。

#2


8  

In my case Oracle was a second connection (stored under oracle key). The application also used PostgreSQL (stored under default key).

在我看来,Oracle是第二个连接(存储在oracle密钥下)。该应用程序还使用PostgreSQL(存储在默认密钥下)。

The problem was that Listener was executed on the default database (PostgreSQL). So I changed code to:

问题是Listener是在默认数据库(PostgreSQL)上执行的。所以我将代码更改为:

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

And all works fine!

一切正常!

#3


-2  

I think this link will help you :

我认为此链接可以帮助您:

Connecting to Oracle with Symfony2 and Doctrine 2.

使用Symfony2和Doctrine 2连接到Oracle。

  1. Map Oracle's DATE type to Doctrine's "date" type instead of "datetime" for Oracle driver
  2. 将Oracle的DATE类型映射到Doctrine的“日期”类型,而不是Oracle驱动程序的“datetime”
  3. Properly configures Doctrine to use most common Oracle Date and DateTime environment configurations. You may or may not need this. Check your Oracle server configuration
  4. 正确配置Doctrine以使用最常见的Oracle Date和DateTime环境配置。您可能需要也可能不需要此功能。检查Oracle服务器配置

https://gist.github.com/johnkary/6481664#file-oracledoctrinetypemappinglistener-php

https://gist.github.com/johnkary/6481664#file-oracledoctrinetypemappinglistener-php