Cakephp update

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, he thinks the value I want to set is a column. Anyone have any idea why this is happening?

+3
source share
3 answers

The problem with the update request puts the value in the quote somehow like

    UPDATE `permissions` AS `Permissions` SET
 `Permissions`.`user` = "counterstaff" WHERE 
`Permissions`.`user` = 'counter' 
-2
source

Fixed! I had to add single quotes around my variable, for example:

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

Source: https://habr.com/ru/post/1781213/


All Articles