Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/http/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用cakephp更新ALL_Cakephp - Fatal编程技术网

如何使用cakephp更新ALL

如何使用cakephp更新ALL,cakephp,Cakephp,我正在尝试进行如下更新: // initialize the array $array = array( "Land Rover" => array("LAND ROVER") ); // loop both arrays foreach($array as $new => $aOld) { foreach($aOld as $old) { $this->updateAll(array('make = $new'), array('make =

我正在尝试进行如下更新:

// initialize the array
$array = array(
    "Land Rover" => array("LAND ROVER")
);

// loop both arrays
foreach($array as $new => $aOld) {
    foreach($aOld as $old) {
        $this->updateAll(array('make = $new'), array('make = $old'));
    }
}
但我得到了一个错误:

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Rover  WHERE `make` = 'LAND ROVER'' at line 1
我所追求的是:

UPDATE items SET make = 'Land Rover' WHERE make = 'LAND ROVER';
请不要给我关于大小写转换的答案,因为我还有其他数组元素,它们比大小写转换更多

如何避免错误?实际上,如何转储完整的sql?我正在
控制台中运行此代码

非常感谢

编辑:我刚刚得到一个SQL的调试:

UPDATE `items` AS `Item`  SET `Item`.`id` = make =  "Land Rover"  WHERE `make` = '\"LAND ROVER\"'

这是一个明显的问题,但它是如何实现的?

您需要自己引用
$fields
参数中的值,如下所示:

更具可读性的版本是:

$this->updateAll(array('make' => "\"$new\""), array('make' => $old));

值和条件应作为关联数组传递

$this->updateAll(
    array(
        'Item.make' => Sanitize::escape($new)
    ),
    array(
        'Item.make' => $old
    )
);
注; 我不在我的计算机后面,也不确定
Sanitize::escape()
是否已经引用了该值,否则

array(
    'Item.make' => "'" . Sanitize::escape($new) . "'"
),

这将是挑战性的帮助你@liyakat我已经有了。通过调整所示的示例,我得到了错误。第一个示例没有产生错误,但没有执行任何操作。第二个将“$new”放在make字段中。
array(
    'Item.make' => "'" . Sanitize::escape($new) . "'"
),
$this->modelname->updateAll(array('make'=>"'$new'"), array('modelname.make'=>$old))

i hope its working