title: PDO query inside a PHP function
body: <p>I have a <code>.php</code> file called <code>functions.php</code> where i must insert functions, for example I have a function called <code>db_connect</code> that connects to my database.</p>
  
  <pre><code>function db_connect()
  {
      $PDO = new PDO('mysql:host=' . DB_HOST . ';dbname=' . DB_NAME . ';charset=utf8', DB_USER, DB_PASS);
      $PDO-&gt;setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  
      return $PDO;
  }
  
  function Test($db)
  {
      $result = false;
      $query = $db-&gt;prepare("SELECT * FROM impressoras");
      $query-&gt;execute();
      #Iterate
      while($row = $query-&gt;fetch(PDO::FETCH_ASSOC)) {
          $result[] = $row;
      }
  
      return $result;
  }
  </code></pre>
  
  <p>The page that is called:</p>
  
  <pre><code>&lt;?php
  
     require('functions.php');
     $con = db_connect();
     print_r(Test($con));
  ?&gt;
  </code></pre>
  
  <p>But this doesn't work, could someone help me? This appears to be error 500.</p>