title: PDO object cant acess inside function
body: <p>In my project i had a file called <code>connection.inc.php</code> which is managing the data base connection using PDO.</p>
  
  <p><strong>include/connection.inc.php</strong></p>
  
  <pre><code> &lt;?php
  $servername = "localhost";
  $username = "root";
  $password = "";
  $dbname = "college";
  
  try {
      $conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
      // set the PDO error mode to exception
      $conn-&gt;setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  
      }
  catch(PDOException $e)
      {
      echo "Error: " . $e-&gt;getMessage();
      }
  ?&gt;
  </code></pre>
  
  <p>i included this file in various other pages and it worked perfectly for me. But when i tried to acess the <code>$conn</code> object inside a function it not working. How to fix this problem. </p>