title: Slim Framework - PDO object created but seems not inside the scope
body: <p>I get this error when I try to test my codes. </p>
  
  <blockquote>
    <p>Call to a member function prepare() on a non-object in ........</p>
  </blockquote>
  
  <p>Below is my codes :</p>
  
  <blockquote>
    <p>ConnectionStrings.php</p>
  </blockquote>
  
  <pre><code>&lt;?php
      $config = require dirname(__FILE__).'../../Configs/Local.php'; 
  
      $host = '127.0.0.1';
      $db   = 'CWW_SecurityDB';
      $user = $config['db']['user'];
      $pass = $config['db']['password'];
      $charset = 'utf8';
  
      $dsn = "mysql:host=$host;dbname=$db;charset=$charset";
      $opt = [
          PDO::ATTR_ERRMODE            =&gt; PDO::ERRMODE_EXCEPTION,
          PDO::ATTR_DEFAULT_FETCH_MODE =&gt; PDO::FETCH_ASSOC,
          PDO::ATTR_EMULATE_PREPARES   =&gt; false,
      ];
  
      $pdo = new PDO($dsn, $user, $pass, $opt);
  
  ?&gt;
  </code></pre>
  
  <blockquote>
    <p>Authentication.php (Related part)</p>
  </blockquote>
  
  <pre><code>&lt;?php
      use \Psr\Http\Message\ServerRequestInterface as Request;
      use \Psr\Http\Message\ResponseInterface as Response;
  
      require dirname(__FILE__).'../../../ConnectionStrings.php';
  
      $app -&gt; group('/authentication', function(){
          $this -&gt;  Get('/login',
          function($request, $response, $args)
          {
              $Username = $request-&gt;getQueryParams()['Username'];
              $Password = $request-&gt;getQueryParams()['Password'];
  
              $sql = 'CALL SEC.usp_GetSecurityUsers(:Username)';
              $stmt = $pdo -&gt; prepare($sql);
              $stmt -&gt; bindParam(':Username', $Username, PDO::PARAM_STR);
              $stmt -&gt; execute();
              .
              .
              . (just a try out on the codes)
  </code></pre>
  
  <p>The problem should lie in the line <strong>$stmt = $pdo -> prepare($sql);</strong>. However, I really could not figure it out after hours. I have read some other posts with similar issue suggesting that the $pdo is out of scope.. but how exactly is my $pdo out of scope in this case? Can someone please enlighten me. Thank you in advance guys :)</p>