I am working on a Symfony project. In one of the entities I have to update a Datetime field, but each time I create a new Datetime object and set it to my entity property and call the flush() function I get an error saying:
An exception occurred while executing UPDATE tablename SET update = ? WHERE id = ? with params ["2015-04-23 15:31:50", 2]
FYI: Everything works fine if I don't update the Datetime field.
//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;
EDIT :
I forgot this:
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
Any ideas on why I get that exception ?
So basically the error was due to the fact that I was using an reserved word update
as a column name in my database -_-
Kudos to @Nemutaisama for helping me figure this out. As he didn't post an answer to this question I am doing it, hope it helps others.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.