doulin2555 2013-03-27 09:45
浏览 9
已采纳

在cakephp中编写查询的困惑

I just have a simple doubt in cakephp, it may be also silly.

Writing queries in cakephp:-

1.$output1 = $this->Modelname->query("Select * from tablename");
2.$output2 = $this->Modelname->query("Update tablename set .....");

When i execute the first query i.e $output1. It runs perfectly. But wen i run $output2 it wont run correctly

What may be the problem ??

  • 写回答

1条回答 默认 最新

  • dongsheng1238 2013-03-27 09:52
    关注

    I would recommend you to use CakePHP methods to query against the database.

    This way, it will be much more secure and things will be easier for you, more even if you have related models.

    At first it can take a while to learn, but you will soon realize the advantages of it.

    Your first query would be equivalent to:

    $this->Modelname->find("all");
    

    And your second one to something like:

    // Update: id is set to a numerical value
    $this->Modelname->id = 2; 
    $this->Modelname->save($this->request->data);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?