我想將一個項目從mssql移植到mysql,使用MySQL Workbench來移植數據庫 - 一切都很順利。試圖插入數據時,我得到SQLSTATE [22007]:無效的日期時間格式:1292錯誤的日期時間值:'06/18/2015 14:49:22'列'x'。在學說配置Entityname.orm.yml我:symfony2學說插入實體datetime mysql格式錯誤
x:
type: datetime
gedmo:
timestampable:
on: create
在實體類:
$em = $this->container->get('doctrine')->getEntityManager();
$new_entity = new EntityName();
$new_entity->setX(new \DateTime());
$em->persist($new_entity);
$em->flush();
在_profiler我發現: INSERT導致錯誤
/**
* @var datetime $x
*/
private $x;
/**
* Set x
*
* @param datetime $x
*/
public function setX($x)
{
$this->x= $x;
}
代碼INTO entity_name(x)VALUES(?)({「1」:{「date」:「2015-06-18 14:49:22」,「timezone_type」:3,「timezone」:「Europe/Bucharest」}} )
並在此之後出現錯誤。
這在以前使用pdo_sqlsrv database_driver和mssql數據庫時有效。
編輯:什麼工作 - 運行set sql_mode = NO_ENGINE_SUBSTITUTION;設置全局sql_mode = NO_ENGINE_SUBSTITUTION;在MySQL數據庫中 - 似乎不好的日期時間格式化不是由symfony完成的。錯誤是由STRICT_TRANS_TABLES造成的 - SQL模式改變MySQL的執行SQL語句
對不起 - 我複製變量的定義錯誤。編輯 –