How to use Doctrine OracleSessionInit listener with Symfony2?

∥☆過路亽.° 提交于 2020-01-01 01:53:15

问题


I am using oracle and I am recieving this error:

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

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

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

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

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

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


回答1:


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.




回答2:


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

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

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

And all works fine!




回答3:


I think this link will help you :

Connecting to Oracle with Symfony2 and Doctrine 2.

  1. Map Oracle's DATE type to Doctrine's "date" type instead of "datetime" for Oracle driver
  2. 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

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



来源:https://stackoverflow.com/questions/8168161/how-to-use-doctrine-oraclesessioninit-listener-with-symfony2

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!