2014-10-29 74 views
0

我使用學說2YiiOracle學說2錯誤ORA-01843:不是有效月份

我有一個DateTime

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

我用這個代碼中插入人表

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

但這個錯誤:

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 

請幫助我。

+0

試試這個:http://stackoverflow.com/questions/14930670/doctrine-2-oracle-datetme-column-showing-not -a化有效本月與上插入實體 – 2014-10-29 09:39:45

回答

0

我解決我的問題,通過執行此:

$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();