方法中的调用方法

时间:2014-04-15 19:05:50

标签: php mysql

我想问一下MVC的哲学 - 模型方面。我有两种方法,getStory& getStoryWithText,哪个getStoryWithText更有效?

 <?php

    public function getStory($storyID) {
    return $this->db->query("SELECT * FROM #__stories WHERE storyID = '$storyID'");
    }

    //variant A
    public function getStoryWithText($storyID) {
    return $this->db->query("SELECT * FROM #__stories s, #__stories_text st WHERE s.storyID = '$storyID' AND s.storyID = st.storyID");
    }

    //variant B
    public function getStoryWithText($storyID) {
    $data["info"] = $this->getStory($storyID);
    $data["text"] = $this->db->query("SELECT * FROM #__stories_text st WHERE st.storyID = '$storyID'");
    return $data;
    }

    ?>

因为一个选择,varint A更好吗?或者变量B更好,因为有更简单的SQL和Iam也调用另一个SQL?将SQL方法调用到另一个方法通常是个好主意,或者我应该为每个可能发生的情况制作SQL。我很困惑,请给我一些建议。

0 个答案:

没有答案