开发者

cakephp updateAll not working

开发者 https://www.devze.com 2023-01-31 22:48 出处:网络
I have the following code: $this->Permissions->updateAll( array(\'Permissions.user\' => $newuser),

I have the following code:

$this->Permissions->updateAll(
    array('Permissions.user' => $newuser), 
    array('Permissions.user' => $originaluser)
);

But when I run it I get the following error:

Warning (512): SQL Error: 1054: Unknown column 'counterstaff' in 'field list' [APP\cake\cake\libs\model\datasources\dbo_source.php, line 681]

Query: UPDATE `permissions` AS `Permissions` SET `Permissions`.`user` = counterstaff WHERE `Permissions`.`user` = 'counter' 

for some reason it thinks the value that I 开发者_运维知识库want to set is a column. Anyone have any ideas why this is the happening?


Fixed it! I had to add single quotes around my variable like so:

$this->Permissions->updateAll(
    array('Permissions.user' => "'".$newuser."'"), 
    array('Permissions.user' => $originaluser)
);


**Use this code for updating your data:** 
$this->Permissions->updateAll(
        array('Permissions.user' => "'$newuser'"), 
        array('Permissions.user' => "'$originaluser'")
    );


Problem with the update query is put the value in quotation something like

    UPDATE `permissions` AS `Permissions` SET
 `Permissions`.`user` = "counterstaff" WHERE 
`Permissions`.`user` = 'counter' 
0

精彩评论

暂无评论...
验证码 换一张
取 消