我想如下做一个updateAll:如何updateAll使用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 = $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\"'
一个明显的问题,但它是如何到达那里?
指这将是挑衅帮助你http://book.cakephp.org/2.0/en/models/saving-your-data.html – liyakat 2013-05-11 11:16:37
@liyakat我已经有了。通过调整所示示例,我得到了错误。 – khany 2013-05-11 11:46:58