我无法更新CakePHP 2.3.1中的记录
查询:
$this -> Staff -> updateAll(array('Staff.last_login' => date('Y-m-d H:i:s')), array('Staff.id' => $staff['Staff']['id']));
错误:
Error: 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
答案 0 :(得分:9)
The $fields array accepts SQL expressions.
Literal values should be quoted manually using Sanitize::escape().
您可以使用
NOW()
但是,在你的情况下,它也适用于引用:
"'" . date('Y-m-d H:i:s') . "'"
答案 1 :(得分:1)
试试这个:
$date = date('Y-m-d H:i:s');
$this->Staff->updateAll(array('Staff.last_login' => "'$date'"), array('Staff.id' => $staff['Staff']['id']));