title: PHP and MySQL. Include Connect-DB out of a function
body: <p>I was just organizing one of my codes and notice that leaving the connect-mydb.php out of a function, it doesnt work. 
  I always thought the include would be loaded prior to any of the functions.</p>
  
  <p>connect-mydb.php</p>
  
  <pre><code>&lt;?php
  $server = 'localhost';
  $user = 'myuser';
  $pass = 'mypass';
  $db = 'mydb';
  $mysqli = new mysqli($server, $user, $pass, $db);
  ?&gt;
  </code></pre>
  
  <p>testdb_out.php (doesnt work)</p>
  
  <pre><code>&lt;?php
  include 'connect-mydb.php';
  
  function UpdateDB() {
  echo "working\n";
  $query = "UPDATE mytable SET myfield = 'aloha' WHERE id = '1'";
  $saved = mysqli_query($mysqli, $query);
  if ($saved) {
    echo 'success';
  }else{
    echo 'failed';
  }
  }
  UpdateDB();
  ?&gt;
  </code></pre>
  
  <p>testdb_within.php (works)</p>
  
  <pre><code>&lt;?php
  function UpdateDB() {
  include 'connect-mydb.php';
  
  $query = "UPDATE mytable SET myfield = 'aloha' WHERE id = '1'";
  $saved = mysqli_query($mysqli, $query);
  if ($saved) {
    echo 'success';
  }else{
    echo 'failed';
  }
  }
  
  UpdateDB();
  ?&gt;
  </code></pre>
  
  <p>In testdb_out, shouldnt the include be loaded prior to the function? That works in other programming languages.</p>