CakePHP 2.3.1 updateAll查询不起作用

时间:2013-04-15 06:14:24

标签: php mysql cakephp cakephp-2.0

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

2 个答案:

答案 0 :(得分: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') . "'"

答案 1 :(得分:1)

试试这个:

$date = date('Y-m-d H:i:s');
$this->Staff->updateAll(array('Staff.last_login' => "'$date'"), array('Staff.id' => $staff['Staff']['id']));