title: PHP undefined variable mysqli connection
body: <p>I have a mysql connection which is included in a separate file:</p>
  
  <pre><code>require 'settings.php';
  </code></pre>
  
  <p>and I have a file with all functions, also included:</p>
  
  <pre><code>require 'functions.php';
  </code></pre>
  
  <p>In the settings there it looks like this:</p>
  
  <pre><code>$db = mysqli_connect("host", "username", "passwort", "database");
      if(!$db) {
          exit("Error: ".mysqli_connect_error());
      }
  </code></pre>
  
  <p>and a function uses this connection like this:</p>
  
  <pre><code>function includehomepage() {
              $data = array();
              $query = "SELECT pagecontent FROM `pages` WHERE `id` = `0`";
              $query = mysqli_query($db, $query);
              $data = mysqli_fetch_assoc($query);
              return $data['pagecontent'];
          }
  </code></pre>
  
  <p>But I get an error message like this:</p>
  
  <pre><code>Undefined variable: db in /var/... on line 18
  </code></pre>
  
  <p>Do you have an answer? The variable have to be defined in the included file.. I am confused. Thanks for your answers!</p>