title: Right place to put query in OOP application
body: <p>I want to build a simple blog application with PHP using OOP concept. So basically I have a Blog class and a Database Class. In Blog class I have a method called "createANewBlog()" which takes a blog text, and a database connection. for example:</p>
  
  <pre><code>class Blog{
    public $id;
    public $text;
  
    public function createANewBlog($inText, $db)
    {
      $this-&gt;text = $inText;
      $this-&gt;id = $db-&gt;create($inText);
      return true; 
    }
  } 
  </code></pre>
  
  <p>so basically this function call a create() function in database class to get the last inserted Id. </p>
  
  <pre><code>class DB{
    function create($intext){
      $sql = "INSERT INTO....... ";
      then i will send the last inserted id;
    }
   } 
  </code></pre>
  
  <p>In the index controller I will simply create a blog object and call that method to create a new object. </p>
  
  <p>Now my question is "Is it the right way to code in OOP" or I sould call the Query inside the blog class createANewBlog() function like:</p>
  
  <pre><code>createANewBlog($inText, $db){
  $this-&gt;text = $inText;
  $this-&gt;id = $db-&gt;execute("INSERT INTO .....");
  
  return true;
  }
  </code></pre>
  
  <p>please help me as I have no idea where is the right place to put the query(Inside the blog class or inside the databse class).  </p>