Mysql 使用条令2 orm在具有时间类型的数据库中保存值
我试图使用ZF2 ORM模块保存数据,使用动态参数作为实体类名,初始化其对象,并使用excel表格标题中的动态值保存数据Mysql 使用条令2 orm在具有时间类型的数据库中保存值,mysql,doctrine-orm,zend-framework2,phpexcel,zfdoctrine,Mysql,Doctrine Orm,Zend Framework2,Phpexcel,Zfdoctrine,我试图使用ZF2 ORM模块保存数据,使用动态参数作为实体类名,初始化其对象,并使用excel表格标题中的动态值保存数据 $time = \PHPExcel_Style_NumberFormat::toFormattedString($rowData[0][$key], 'hh:mm:ss'); $obj->$setter(\DateInterval::createFromDateString($this->secondsToTime(strtotime($time)))); $th
$time = \PHPExcel_Style_NumberFormat::toFormattedString($rowData[0][$key], 'hh:mm:ss');
$obj->$setter(\DateInterval::createFromDateString($this->secondsToTime(strtotime($time))));
$this->orm->persist($obj);
$this->orm->flush();
$this->secondsToTime(strotime($time))以格式4返回时间
小时5分6秒
字段类型是时间,当我打印$obj->getter()时,它打印:
DateInterval Object
(
[y] => 0
[m] => 0
[d] => 0
[h] => 4
[i] => 5
[s] => 6
[weekday] => 0
[weekday_behavior] => 0
[first_last_day_of] => 0
[invert] => 0
[days] =>
[special_type] => 0
[special_amount] => 0
[have_weekday_relative] => 0
[have_special_relative] => 0
)
但它并没有将其值保存为数据库中的4:05:06,而是保存了00:00:00。
我试着从栏中回答什么类型?我认为应该使用\Datetime php对象而不是DateInterval,并将其映射为一个。希望这有帮助这很疯狂,我以前用过,但有错误,现在它工作了,我可能错过了一些东西所以你不更改你的代码?现在正确地保存在db上?字段的列类型是什么?@Matteo我的意思是我早些时候尝试了Datetime(),但出现了错误,现在我再次尝试,它工作得很好。我可能错过了一些东西,它让人相信DateTime将不起作用,这就是为什么我尝试其他东西,字段类型是time