1

我无法更新 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

4

2 回答 2

9

请参阅http://book.cakephp.org/2.0/en/models/saving-your-data.html#model-updateall-array-fields-array-conditions

The $fields array accepts SQL expressions. 
Literal values should be quoted manually using Sanitize::escape().

您可以使用

NOW()

但是,在您的情况下,它也适用于引用:

"'" . date('Y-m-d H:i:s') . "'"
于 2013-04-15T13:31:06.190 回答
0

尝试这个:

$date = date('Y-m-d H:i:s');
$this->Staff->updateAll(array('Staff.last_login' => "'$date'"), array('Staff.id' => $staff['Staff']['id']));
于 2014-05-12T05:08:58.733 回答