"literal does not match format string" 使用 Doctrine ORM & Zend2 & Oracle 保存日期时
"literal does not match format string" when saving dates using Doctrine ORM & Zend2 & Oracle
当我尝试使用 Doctrine ORM 保存 Date 或 DateTime 字段时,特别是在 Zend2+Oracle 中,我收到以下错误:
An exception occurred while executing 'INSERT INTO NEWS (ID, TITLE, SLUG, CONTENT, ACTIVE, PUBLISH_DATE, CATEGORY_ID) VALUES (?, ?, ?, ?, ?, ?, ?)' with params [23, "some title", "some-slug", "some content", "1", "2016-06-18 00:00:00", 2]:
ORA-01861: literal does not match format string
经过一番搜索,我发现这背后的原因很可能是ORM中的一个错误,OracleSessionInit在使用Oracle时没有正确初始化,因此没有加载NLS或其他环境设置,这意味着日期没有被正确处理。
我已经通过更换线路修复了它
return EntityManager::create($connection, $config);
在文件中:\vendor\doctrine\doctrine-orm-module\src\DoctrineORMModule\Service\EntityManageFactory.php
,函数下createService.php
包含以下几行:
$em = EntityManager::create($connection, $config);
$dbh = $em->getConnection();
$sth = $dbh->prepare("ALTER SESSION SET NLS_DATE_FORMAT='YYYY-MM-DD HH24:MI:SS'");
$sth->execute();
return $em;
当我尝试使用 Doctrine ORM 保存 Date 或 DateTime 字段时,特别是在 Zend2+Oracle 中,我收到以下错误:
An exception occurred while executing 'INSERT INTO NEWS (ID, TITLE, SLUG, CONTENT, ACTIVE, PUBLISH_DATE, CATEGORY_ID) VALUES (?, ?, ?, ?, ?, ?, ?)' with params [23, "some title", "some-slug", "some content", "1", "2016-06-18 00:00:00", 2]:
ORA-01861: literal does not match format string
经过一番搜索,我发现这背后的原因很可能是ORM中的一个错误,OracleSessionInit在使用Oracle时没有正确初始化,因此没有加载NLS或其他环境设置,这意味着日期没有被正确处理。
我已经通过更换线路修复了它
return EntityManager::create($connection, $config);
在文件中:\vendor\doctrine\doctrine-orm-module\src\DoctrineORMModule\Service\EntityManageFactory.php
,函数下createService.php
包含以下几行:
$em = EntityManager::create($connection, $config);
$dbh = $em->getConnection();
$sth = $dbh->prepare("ALTER SESSION SET NLS_DATE_FORMAT='YYYY-MM-DD HH24:MI:SS'");
$sth->execute();
return $em;