Symfony实体日期时间字段更新失败

时间:2015-04-23 15:40:39

标签: php symfony datetime doctrine

我正在开发一个Symfony项目。在其中一个实体中,我必须更新Datetime字段,但每次我创建一个新的Datetime对象并将其设置为我的实体属性并调用flush()函数时,我会收到一条错误消息:

An exception occurred while executing UPDATE tablename SET update = ? WHERE id = ? with params ["2015-04-23 15:31:50", 2]

仅供参考:如果我不更新日期时间字段,一切正常。

//Here is what I set to the Datetime field:
$eo->setUpdate();

//The function in the Entity
public function setUpdate() {
    $this->update = new \DateTime('now', new \DateTimeZone('UTC'));

    return $this;
}

//And the field declaration
/**
 * @var \DateTime
 *
 * @ORM\Column(name="update", type="datetime", nullable=false)
 */
private $update;

编辑

我忘了这个:

SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near "update = "2015-04-23 15:53:29" WHERE id = 2" at line 1

关于我为什么会遇到这种例外的任何想法?

1 个答案:

答案 0 :(得分:0)

所以基本上错误是由于我在我的数据库中使用保留字update作为列名-_-

感谢@Nemutaisama帮助我解决这个问题。由于他没有回答这个问题我正在做这件事,希望它能帮助别人。

相关问题