title: How to fill classes with data from database
body: <p>I created two classes in my example. These classes represent respectively <em>{Author}</em> and <em>{BlogPost}</em>. I know how to fetch and write information from/to these classes. My question is about processing information from a database.</p>
  
  <p>Do properties have to fetch data from a database class? The problem is I don't know how to fill a class with data from my database. The connection with the database isn't the problem. It is all about the way I can fill the class with data from my database.</p>
  
  <pre><code>&lt;?php
  
  class Author{
  
      private $naam;
      private $biografie;
      private $avatar;
  
  public function getNaam() {
      print($this-&gt;naam);
  }
  
  public function getBiografie() {
      print($this-&gt;biografie);
  }
  
  public function getAvatar() {
      print($this-&gt;avatar);
  }
  
  public function setNaam($naam) {
      $this-&gt;naam = $naam;
  }
  
  public function setBiografie($biografie) {
      $this-&gt;biografie = $biografie;
  }
  
  public function setAvatar($avatar) {
      $this-&gt;avatar = $avatar;
  }
  
  }
  
  class BlogPost{
  
      private $titel;
      private $content;
      private $author;
  
  public function __construct() {
      $this-&gt;author = new Author;
  }
  
  public function getTitel() {
      print($this-&gt;titel);
  }
  
  public function getContent() {
      print($this-&gt;content);
  }
  
  public function getAuthor() {
      print($this-&gt;author-&gt;getNaam());
  }
  
  public function setTitel($titel) {
      $this-&gt;titel = $titel;
  }
  
  public function setContent($content) {
      $this-&gt;content = $content;
  }
  
  }
  
  ?&gt;
  </code></pre>
  
  <p>I know how to get data from my database by writing queries, but I don't know to proces the data in my class.</p>
  
  <p>Do I have to link my properties to the database? </p>
  
  <pre><code>private $naam = Database::getName();
  </code></pre>
  
  <p>Or do I need to write a query in my get or set method?</p>