title: OOP PHP with Mysql Database
body: <p>If we have a code like this:</p>
  
  <pre><code>class Game {
      private $_id;
      private $_name;
      private $_url;
  
      public function __construct($_id,$_name,$_url){
          $this-&gt;_id = $_id;
          $this-&gt;_name = $_name;
          $this-&gt;_url = $_url;
      }
  }
  </code></pre>
  
  <p>And we want to simply connect to our Database to get a game by id, where do we place the 'getByID' function?</p>
  
  <p>Do we place it within the 'Game Class' as 'static function', do we put it in the 'Database Connection Class' as 'public function' or do we just put the method in the 'general functions inside the main index.php' as 'function'?</p>
  
  <p>I currenctly have choosen for a 'static function' within the 'Game Class':</p>
  
  <pre><code>public static function getByID($id,$db){    
      $query = "SELECT * FROM game WHERE id = :id LIMIT 1";
      $prepare = array(":id"=&gt;$id);
      $result = $db-&gt;Precute($query,$prepare);
      foreach($result as $r) return new Game($r['id'],$r['name'],$r['url']);
      return null;
  }
  </code></pre>
  
  <p>(Precute is a custom function within the Database Class to prepare and execute the query)
  How would you approach this?</p>