I'm using Doctrine 2 and Yii and Oracle
.
I have a DateTime
field
/**
* @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. Just need 2 EventListeners and activate them in the service definition as per this gist - 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();
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.