title: Use of MySQLi within a class
body: <pre><code>function __construct(mysqli $db, $country = NULL, $sport = NULL) {
      $this-&gt;db = $db;
      $this-&gt;country = base64_decode($country);
      $this-&gt;sport = base64_decode($sport);
  }
  
  public function GetColor($colorcode) {
      $query = 'SELECT naam_nl FROM colors WHERE code = $colorcode';
      $result = $this-&gt;db-&gt;query($query);
      while ($row = $result-&gt;fetch_assoc()) { // Line 21
          echo $row['naam_nl'];
      }
      $result-&gt;close();
  }
  </code></pre>
  
  <p>Gives me:</p>
  
  <pre><code>Fatal error: Call to a member function fetch_assoc() on a non-object in /home/cloud/public/td/teamdresser.class.php on line 21
  </code></pre>
  
  <p>So I tried:</p>
  
  <pre><code>    $result = $this-&gt;db-&gt;query($query);
      while ($row = $this-&gt;db-&gt;fetch_assoc($result)) {
          echo $row['naam_nl'];
      }
  </code></pre>
  
  <p>And then...</p>
  
  <pre><code>Fatal error: Call to undefined method mysqli::fetch_assoc() in /home/cloud/public/td/teamdresser.class.php on line 21
  </code></pre>
  
  <p>I'm doing something wrong.. Can someone point me in the right direction?</p>