yii框架,绑定Params不工作

时间:2014-09-02 12:58:52

标签: php sql yii parameters param

我有这部分代码,但它不会保存更改。你能告诉我:为什么?

        $var1 = $this->url_path."/";
        $var2 = $this->oldUrlPath."/";
        $var3 = $this->url_path."/%";

        $query = "UPDATE page SET url_path = REPLACE(url_path, :oldUrlPath, :url) WHERE          url_path LIKE :urlLike AND section_id = ".$this->section_id;
        $command=Yii::app()->db->createCommand($query);
        $command->bindParam(':url',$var1, PDO::PARAM_STR);
        $command->bindParam(':urlLike',$var3, PDO::PARAM_STR);
        $command->bindParam(':oldUrlPath',$var2, PDO::PARAM_STR);
        if(!$command->query()) throw new CDbException(tb('Cannot update children pages'));

1 个答案:

答案 0 :(得分:0)

如果查询不返回数据集 - INSERTUPDATEDELETE - 您应该使用$command->execute()

如果查询返回数据集,请使用$command->query(),例如SELECT

http://www.yiiframework.com/doc/api/1.1/CDbCommand#execute-detail

http://www.yiiframework.com/doc/api/1.1/CDbCommand#query-detail