title: Variables Undefined when in Function
body: <p>I am working on a project, and I am getting undefined errors for $host, $dbname, $user, and $pass.  </p>
  
  <p>But the errors only occur when those are inside of the dbConnect() function.</p>
  
  <p>Here's the code (upload.php):</p>
  
  <pre><code>&lt;?php
  error_reporting(E_ALL);
  require('config.php');
  
  $filename = htmlentities($_FILES['file']['name']);
  $tmpname = $_FILES['file']['tmp_name'];
  $filesize = $_FILES['file']['size'];
  $filetype = $_FILES['file']['type'];    
  
  function dbConnect() {
  
      try {
          global $dbcon;
          $dbcon = new PDO("mysql:host=$host;dbname=$dbname", $user, $pass);
      }
      catch (PDOException $e) {
          echo $e-&gt;getMessage();
      }
  }
  
  if (dbConnect()) {
      print('worked');
  }
  </code></pre>
  
  <p>config.php:</p>
  
  <pre><code>&lt;?php
  global $host, $user, $pass, $dbname;
  
  $host =  "localhost"; // MySQL Hostname
  $user = "root"; // MySQL User
  $pass = "mypass"; // MySQL Password
  $dbname = "files";
  </code></pre>