title: PHP mysqli Fatal error: Call to a member function query() on null
body: <p>Im getting this error and i dont know how to fix.</p>
  
  <p><code>'Fatal error: Call to a member function query() on null in C:\xampp\htdocs\cms\lib\db.php on line 46'</code></p>
  
  <p>Code:</p>
  
  <pre><code>class db {
  
  public $mysqli;
  
  function Connect() {
  
           $server = 'localhost';
          $dbusername = 'root';
          $database = 'cms';
          $dbpassword = 'lopaka';
          $this-&gt;mysqli = new mysqli($server, $dbusername, $dbpassword, $database);
  
          /* connectie bekijken */
          if (mysqli_connect_errno()) {
              printf("Connectie mislukt: %s\n", mysqli_connect_error());
              exit();
          }
      }
  
  
  function GetGallery() {
  
      $query = "SELECT * FROM menu";
      $action = $this-&gt;mysqli-&gt;query($query);
  
      while ($row = $action-&gt;fetch_assoc()) {
          $gallery .= '&lt;a href="'.$siteurl.''.$row['url'].'" title="'.$row['alt'].'" data-gallery="" &gt;&lt;img src="'.$siteurl.''.$row['url'].'" width="75px" height="75px"&gt;&lt;/a&gt;';    
      }
  
      return $gallery;
  } 
  </code></pre>
  
  <p>}</p>
  
  <p>Thanks !!!</p>
  
  <p>Edit - works now, but now i have some new errors:</p>
  
  <p>Notice: Undefined index: url in C:\xampp\htdocs\cms\lib\db.php on line 42</p>
  
  <p>Notice: Undefined index: alt in C:\xampp\htdocs\cms\lib\db.php on line 42</p>
  
  <p>Notice: Undefined index: url in C:\xampp\htdocs\cms\lib\db.php on line 42</p>