php - 不正确的日期时间值:第 1 行的列“date_updated”的“1540564519”保存模型 Phalcon?
问题描述
我正在尝试将数据保存在表格中,但是当我保存它时会引发以下错误:
SQLSTATE [22007]:日期时间格式无效:1292 日期时间值不正确:第 1 行的列“date_updated”的“1540564519”保存模型评估补救措施
evaluation_remedy 表架构:
--
-- Table structure for table `evaluation_remedy`
--
CREATE TABLE IF NOT EXISTS `evaluation_remedy` (
`id` int(10) unsigned NOT NULL,
`title` varchar(255) NOT NULL,
`description` text NOT NULL,
`diet` text NOT NULL,
`is_local_food_store` tinyint(4) NOT NULL DEFAULT '0',
`product_image` varchar(255) DEFAULT NULL,
`product_description` text,
`product_url` varchar(255) DEFAULT NULL,
`importance` tinyint(4) NOT NULL DEFAULT '0',
`is_active` tinyint(4) NOT NULL DEFAULT '1',
`date_created` datetime DEFAULT NULL,
`date_updated` datetime DEFAULT NULL
) ENGINE=InnoDB AUTO_INCREMENT=64 DEFAULT CHARSET=utf8;
--
-- Indexes for table `evaluation_remedy`
--
ALTER TABLE `evaluation_remedy`
ADD PRIMARY KEY (`id`);
--
-- AUTO_INCREMENT for dumped tables
--
--
-- AUTO_INCREMENT for table `evaluation_remedy`
--
ALTER TABLE `evaluation_remedy`
MODIFY `id` int(10) unsigned NOT NULL AUTO_INCREMENT,AUTO_INCREMENT=64;
让我知道是否需要任何其他信息。我很乐意分享解决方案所需的任何内容。
存储/保存功能:
public function saveEvaluationRemedyAction(){
// Instantiate new form for Evaluation Symptom Model
$form = new EbEvaluationRemedyForm();
if( $form ->isValid($this->request->getPost())){
// Get the Evaluation Symptom id (if any)
$id = $this->request->get( 'id', null );
// Get existing Evaluation Symptom (if any) or create a new one
if( null !== $id && $id !== '' ){
$evaluationRemedy = CxEbEvaluationRemedy::findFirst( $id );
} else {
$evaluationRemedy = new CxEbEvaluationRemedy();
}
// Bind form with post data
$form->bind( $this->request->getPost(), $evaluationRemedy );
// Save the form with new data
$evaluationRemedy->save();
// Saving linked remedies in Related Remedy Table
$remedies = $this->request->get('remedies_list');
if($remedies){
foreach ($remedies as $key => $remedy) {
$relatedRemedy = CxEbEvaluationRemedy::getIdByName($remedy);
$remedyObject = new CxEbEvaluationRemedyRelated();
$remedyObject->setEvaluationRemedyId($evaluationRemedy->getId());
$remedyObject->setEvaluationRelatedRemedyId($relatedRemedy['id']);
$remedyObject->save();
}
}
} else {
// Send error Json response
return CxHelper::SendJsonError($form->getHtmlFormattedErrors());
}
// Return success
return array( 'data' => 'Success' );
}
让我知道是否需要任何其他信息。我很乐意分享解决方案所需的任何内容。
谢谢
解决方案
像这样从大纪元转换它:
<?php
$date = new DateTime('@1540564519');
$formatted = $date->format('Y-m-d H:i:s');
echo $formatted; // 2018-10-26 14:35:19
推荐阅读
- pine-script - 如何从版本 2 转换为版本而不会在 pinescript 中出现未清除的 indentiier 错误?
- docker - 无法从 Springboot 应用程序连接 Kafka
- r - 根据条件将多列中的值替换为另一列的值
- html - 如何改变一个使用特定的数字格式?
- python - Django ORM:相当于 SQL `NOT IN`?`exclude` 和 `Q` 对象不起作用
- r - 物种积累图中的传说
- arrays - Excel VBA - 比较两个数组并返回一个数组中但不在另一个数组中的字符串
- css - Bootstrap 4 / Bootstrap VUE:无法覆盖@mixin bg-variant的颜色
- angular - 可重复使用的自定义元素角度
- python - 如何在django的另一个表中插入主键值