1

我正在尝试按如下方式进行 updateAll:

// 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?我在Console.

非常感谢。

编辑:我刚刚得到了 SQL 的调试:

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

一个明显的问题,但它是如何到达那里的?

4

3 回答 3

2

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

$this->updateAll(
    array(
        'Item.make' => Sanitize::escape($new)
    ),
    array(
        'Item.make' => $old
    )
);

笔记; 我不在我的电脑后面,也不确定是否Sanitize::escape()已经引用了该值,否则;

array(
    'Item.make' => "'" . Sanitize::escape($new) . "'"
),
于 2013-05-11T12:31:03.697 回答
0

您需要自己引用$fields参数中的值,就像API说的那样:

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

更易读的版本是:

$this->updateAll(array('make' => "\"$new\""), array('make' => $old));
于 2013-05-11T11:53:05.003 回答
0
$this->modelname->updateAll(array('make'=>"'$new'"), array('modelname.make'=>$old))

i hope its working
于 2013-05-13T06:29:32.613 回答