title: Unable to use PDO methods when using DB class
body: <p>Hey guys I'm doing this wrong again I'm sure, but I'm trying to instantiate a PDO database 
  handler from my class Database from the file class.database.php inside my class AdminSession 
  from class.admin.php, somethings a bit screwy with my dependancy injection, and it is not
  allowing me to use PDO's methods corretly; like fetch(), prepare() etcetra.</p>
  
  <p>the class.database.php file</p>
  
  <pre><code>class Database
  {
      public $db;   // handle of the db connection
  
      private static $dsn="mysql:host=server2.com;dbname=database";
      private static $user="user";
      private static $pass="pass";
      private static $instance;
  
      public function __construct () 
      {
          $this-&gt;db = new PDO(self::$dsn,self::$user,self::$pass,$self::$opts);
          $this-&gt;db-&gt;setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
          $this-&gt;db-&gt;setAttribute(PDO::MYSQL_ATTR_INIT_COMMAND, "SET NAMES 'utf8'");
  
          switch($_SERVER['ENVIRONMENT']) {
              case 'staging':
                  self::$dsn="mysql:host=server1.com;dbname=database";
                  self::$user="user";
                  self::$pass="pass";
                  break;
              default:
                  self::$dsn="mysql:host=server2.com;dbname=database";
                  self::$user="user";
                  self::$pass="pass";
          }
  
      }
  
      public static function getInstance()
      {
          if(!isset(self::$instance))
          {
              $object= __CLASS__;
              self::$instance=new $object;
          }
          return self::$instance;
      }
  
  }
  </code></pre>
  
  <p>and here's the topmost of my class.admin.php, and a method that is throwing an error.
  right now the errors I'm getting</p>
  
  <p><strong>PHP Fatal error:  Call to undefined method line 230</strong></p>
  
  <p>If I use <code>$this-&gt;db-prepare($sql)</code></p>
  
  <p>or</p>
  
  <p><strong>PHP Fatal error:  Call to a member function prepare() on a non-object  line 230</strong></p>
  
  <p>If I use <code>$db-prepare($sql)</code></p>
  
  <pre><code>require('library/class.database.php');
  
  class AdminSession {
      static $abs_path;
  
      public function __construct(Database $db) {
          session_start();
  
          self::$abs_path = dirname(dirname(__FILE__));
          if($_SERVER['REQUEST_METHOD'] == 'POST') {
  
              $this-&gt;post = $_POST; // filter_input_array(INPUT_POST, FILTER_SANITIZE_STRING);
  
              if(get_magic_quotes_gpc ()) {
                  //get rid of magic quotes and slashes if present
                  array_walk_recursive($this-&gt;post, array($this, 'stripslash_gpc'));
              }
          }
  
          $this-&gt;get = $_GET; // filter_input_array(INPUT_GET, FILTER_SANITIZE_STRING);
          array_walk_recursive($this-&gt;get, array($this, 'urldecode'));
      }
  
  // other methods
  
      private function checkDB($username, $password) {
          $sql = "SELECT * FROM users WHERE username=:username";
          try {
  
              $db             = Database::getInstance();
              $stmt           = $db-&gt;prepare($sql);
  
                  $stmt-&gt;bindParam("username", $username);
                  $stmt-&gt;execute();
  
              $user           = $stmt-&gt;fetchAll(PDO::FETCH_OBJ);
  
              $db = null;
  
              if($user) {
                  //general return
                  if(is_object($user[0]) &amp;&amp; md5($user[0]-&gt;password) == $password) {
                      return true;
                  } else {
                      return false;
                  }
              } else {
                  return false;
              }
  
          } catch(PDOException $e) {
              echo '{"error":{"text":'. $e-&gt;getMessage() .'}}';
          }
  
      }
  
  }
  </code></pre>