简体   繁体   English

教义2错误ORA-01843:无效月份

[英]Doctrine 2 error ORA-01843: not a valid month

I'm using Doctrine 2 and Yii and Oracle . 我正在使用Doctrine 2YiiOracle

I have a DateTime field 我有一个DateTime字段

    /**
     * @var \DateTime
     *
     * @ORM\Column(name="CREATE_DATE", type="datetime", nullable=true)
     */
    private $createDate;

I used this code to insert person to the table 我用这段代码将人插入表格

        $date = new \DateTime("now");
        $person = new Person();
        $person->setCreateDate($date);
        $person->setLastName('name');
        $entityManager->persist($person);
        $entityManager->flush();

but it return this error: 但它返回此错误:

An exception occurred while executing 'INSERT INTO PERSON (PERSON_ID, CREATE_DATE, LAST_NAME) VALUES (?, ?, ?)' with params [27, "2014-10-29 09:23:38", "name"]:

ORA-01843: not a valid month 

please help me. 请帮我。

If someone is using Doctrine with Symfony , it's much easier. 如果有人在Symfony中使用Doctrine ,那会容易得多。 Just need 2 EventListeners and activate them in the service definition as per this gist - https://gist.github.com/phpfour/4290cc1f0892dda4ef94a492d6b3f81e 只需要2个EventListener并按照此要点在服务定义中激活它们-https: //gist.github.com/phpfour/4290cc1f0892dda4ef94a492d6b3f81e

I solved my problem by execute this: 我通过执行以下命令解决了我的问题:

   $em  = $this->getEntityManager();
   $dbh = $em->getConnection();
   $sth = $dbh->prepare("ALTER SESSION SET NLS_TIME_FORMAT = 'HH24:MI:SS' NLS_DATE_FORMAT = 'YYYY-MM-DD HH24:MI:SS' NLS_TIMESTAMP_FORMAT = 'YYYY-MM-DD HH24:MI:SS' NLS_TIMESTAMP_TZ_FORMAT = 'YYYY-MM-DD HH24:MI:SS TZH:TZM'");
   $sth->execute();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM