如何在cakephp

时间:2016-04-21 06:49:36

标签: cakephp cakephp-2.0 cakephp-2.3 cakephp-2.1

$test="test's";   
$contact='1234567890';
 $this->Page->updateAll(
        array('Page.order' => 0,"Page.name" => "'$test'","Page.contact" => "'$contact'"),
        array('Page.type' => 'PROMOTED')
    );

以上查询有单引号冲突。有没有其他方法来编写更新查询。我正在使用cakephp 2x

1 个答案:

答案 0 :(得分:0)

注意:如果要将它们识别为字符串变量字符,则必须在php中反斜杠具有其他含义的字符。例如(测试需要测试

  

http://book.cakephp.org/2.0/en/models/saving-your-data.html#model-updateall-array-fields-mixed-conditions

尝试:

$db = $this->getDataSource();
$test = $db->value('test\'s');
$contact = $db->value('1234567890');
$this->Page->updateAll(
        array('Page.order' => 0,"Page.name" => $test,"Page.contact" =>     $contact),
    array('Page.type' => 'PROMOTED')
);