title: Keep getting Fatal error: Call to undefined method DB::prepare()
body: <p>That's the response for <code>Reflection::export(new ReflectionClass($this));</code> </p>
  
  <pre><code>Class [ class Users extends Crud ] { 
      @@ C:\xampp\htdocs\classes\Users.php 5-76 
  - Constants [0] { 
  } 
  
  - Static properties [0] { 
  } 
  
  - Static methods [0] {
  } 
  
  - Properties [7] {
      Property [ protected $table ]
      Property [ private $username ]
      Property [ private $email ]
      Property [ private $password ]
      Property [ private $passwordRepeat ] 
      Property [ private $nickname ] 
      Property [ private $permission ] 
  } 
  - Methods [20] {
      Method [ public method setUsername ] {
      @@ C:\xampp\htdocs\classes\Users.php 15 - 17 
  - Parameters [1] { 
      Parameter #0 [ $username ] 
  } 
  } Method [ public method setEmail ] {
      @@ C:\xampp\htdocs\classes\Users.php 19 - 21 
  - Parameters [1] {
      Parameter #0 [ $email ] 
  } 
  } Method [ public method setPassword ] {
      @@ C:\xampp\htdocs\classes\Users.php 23 - 28 
  - Parameters [2] { 
      Parameter #0 [ $password ] 
      Parameter #1 [ $passwordRepeat ] 
  }
  } Method [ public method setNickname ] { 
      @@ C:\xampp\htdocs\classes\Users.php 30 - 32 
  - Parameters [1] { 
      Parameter #0 [ $nickname ] 
  } 
  } Method [ public method setPermission ] {
      @@ C:\xampp\htdocs\classes\Users.php 34 - 36 
  - Parameters [1] { 
      Parameter #0 [ $permission ] 
  } 
  } Method [ public method checkUsername ] {
      @@ C:\xampp\htdocs\classes\Users.php 38 - 49 
  - Parameters [2] {
      Parameter #0 [ $username ] 
      Parameter #1 [ $email ] 
  } 
  } Method [ public method insert ] {
      @@ C:\xampp\htdocs\classes\Users.php 51 - 64
  } Method [ public method update ] {
      @@ C:\xampp\htdocs\classes\Users.php 66 - 75 - Parameters [1] {
  Parameter #0 [ $id ] 
  } 
  } Method [ public method find ] {
      @@ C:\xampp\htdocs\classes\Crud.php 12 - 18 
  - Parameters [1] {
      Parameter #0 [ $id ] 
  } 
  } Method [ public method findAll ] {
      @@ C:\xampp\htdocs\classes\Crud.php 20 - 26 
  } Method [ public method delete ] { 
      @@ C:\xampp\htdocs\classes\Crud.php 28 - 33 
  - Parameters [1] {
      Parameter #0 [ $id ] 
  } 
  } /** * Create a new DB object for the specified database type but don't * connect to the database * * @param string $type the database type (eg "mysql") * @param array $options an associative array of option names and values * * @return object a new DB object. A DB_Error object on failure. * * @see DB_common::setOption() */ 
  Method [ public method &amp;factory ] {
      @@ C:\xampp\php\pear\DB.php 447 - 480 
  - Parameters [2] {
      Parameter #0 [ $type ] 
      Parameter #1 [ $options = false ] 
  } 
  } /** * Create a new DB object including a connection to the specified database * * Example 1. * * require_once 'DB.php'; * * $dsn = 'pgsql://user:password@host/database'; * $options = array( * 'debug' =&gt; 2, * 'portability' =&gt; DB_PORTABILITY_ALL, * ); * * $db =&amp; DB::connect($dsn, $options); * if (PEAR::isError($db)) { * die($db-&gt;getMessage()); * } * * * @param mixed $dsn the string "data source name" or array in the * format returned by DB::parseDSN() * @param array $options an associative array of option names and values * * @return object a new DB object. A DB_Error object on failure. * * @uses DB_dbase::connect(), DB_fbsql::connect(), DB_ibase::connect(), * DB_ifx::connect(), DB_msql::connect(), DB_mssql::connect(), * DB_mysql::connect(), DB_mysqli::connect(), DB_oci8::connect(), * DB_odbc::connect(), DB_pgsql::connect(), DB_sqlite::connect(), * DB_sybase::connect() * * @uses DB::parseDSN(), DB_common::setOption(), PEAR::isError() */ 
  Method [ public method &amp;connect ] {
      @@ C:\xampp\php\pear\DB.php 518 - 567 
  - Parameters [2] {
      Parameter #0 [ $dsn ] 
      Parameter #1 [ $options = Array ] 
  } 
  } /** * Return the DB API version * * @return string the DB API version number */ 
  Method [ public method apiVersion ] {
      @@ C:\xampp\php\pear\DB.php 577 - 580 
  } /** * Determines if a variable is a DB_Error object * * @param mixed $value the variable to check * * @return bool whether $value is DB_Error object */
  
  Method [ public method isError ] {
      @@ C:\xampp\php\pear\DB.php 592 - 595 
  - Parameters [1] {
      Parameter #0 [ $value ] 
  } 
  } /** * Determines if a value is a DB_ object * * @param mixed $value the value to test * * @return bool whether $value is a DB_ object */ 
  Method [ public method isConnection ] {
      @@ C:\xampp\php\pear\DB.php 607 - 612 
  - Parameters [1] {
      Parameter #0 [ $value ] 
  } 
  } /** * Tell whether a query is a data manipulation or data definition query * * Examples of data manipulation queries are INSERT, UPDATE and DELETE. * Examples of data definition queries are CREATE, DROP, ALTER, GRANT, * REVOKE. * * @param string $query the query * * @return boolean whether $query is a data manipulation query */ 
  Method [ public method isManip ] {
      @@ C:\xampp\php\pear\DB.php 628 - 639 
  - Parameters [1] {
      Parameter #0 [ $query ] 
  } 
  } /** * Return a textual error message for a DB error code * * @param integer $value the DB error code * * @return string the error message or false if the error code was * not recognized */ 
  Method [ public method errorMessage ] {
      @@ C:\xampp\php\pear\DB.php 652 - 694 
  - Parameters [1] {
      Parameter #0 [ $value ] 
  } 
  } /** * Parse a data source name * * Additional keys can be added by appending a URI query string to the * end of the DSN. * * The format of the supplied DSN is in its fullest form: * * phptype(dbsyntax)://username:password@protocol+hostspec/database?option=8&amp;another=true * * * Most variations are allowed: * * phptype://username:password@protocol+hostspec:110//usr/db_file.db?mode=0644 * phptype://username:password@hostspec/database_name * phptype://username:password@hostspec * phptype://username@hostspec * phptype://hostspec/database * phptype://hostspec * phptype(dbsyntax) * phptype * * * @param string $dsn Data Source Name to be parsed * * @return array an associative array with the following keys: * + phptype: Database backend used in PHP (mysql, odbc etc.) * + dbsyntax: Database used with regards to SQL syntax etc. * + protocol: Communication protocol to use (tcp, unix etc.) * + hostspec: Host specification (hostname[:port]) * + database: Database to use on the DBMS server * + username: User name for login * + password: Password for login */ Method [ public method parseDSN ] { @@ C:\xampp\php\pear\DB.php 733 - 850 - Parameters [1] { Parameter #0 [ $dsn ] } } /** * Returns the given DSN in a string format suitable for output. * * @param array|string the DSN to parse and format * @param boolean true to hide the password, false to include it * @return string */ 
  Method [ public method getDSNString ] {
      @@ C:\xampp\php\pear\DB.php 862 - 926 
  - Parameters [2] {
      Parameter #0 [ $dsn ] 
      Parameter #1 [ $hidePassword ] 
  }}}} 
  </code></pre>
  
  <p>With the  <code>Reflection::export(new ReflectionClass('DB'));</code>
  I got the following response:</p>
  
  <pre><code>Class [ class DB ] { 
      @@ C:\xampp\htdocs\classes\DB.php 5-30 
  
  - Constants [0] { 
  } 
  
  - Static properties [1] { 
      Property [ private static $instance ] 
  } 
  
  - Static methods [2] { 
      Method [ static public method getInstance ] {
          @@ C:\xampp\htdocs\classes\DB.php 9 - 24 
  } 
  
      Method [ static public method prepare ] { 
          @@ C:\xampp\htdocs\classes\DB.php 26 - 28 - Parameters [1] { 
              Parameter #0 [ $sql ] 
          } 
      } 
  } 
  
  - Properties [0] {
   } 
  
  - Methods [0] { 
  } }
  </code></pre>
  
  <p>So, I'm new with PHP and I'm trying to learn a little bit of PDO.
  I have this code and it keeps showing this message:</p>
  
  <blockquote>
    <p>Fatal error: Call to undefined method DB::prepare() in C:\xampp\htdocs\classes\Crud.php on line 22</p>
  </blockquote>
  
  <p>Here's my DB.php:</p>
  
  <pre><code>&lt;?php
  
  require_once 'cfg.php';
  
  class DB{
  
  private static $instance;
  
  public static function getInstance(){
  
      if(!isset(self::$instance)){
  
          try {
              self::$instance = new PDO('mysql:host=' . DB_HOST . ';dbname=' . DB_NAME, DB_USER, DB_PASS);
              self::$instance-&gt;setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
              self::$instance-&gt;setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_OBJ);
          } catch (PDOException $e) {
              echo $e-&gt;getMessage();
          }
  
      }
  
      return self::$instance;
  }
  
  public static function prepare($sql){
      return self::getInstance()-&gt;prepare($sql);
  }
  
  }
  ?&gt;
  </code></pre>
  
  <p>Crud.php:</p>
  
  <pre><code>&lt;?php
  
  require_once 'DB.php';
  
  abstract class Crud extends DB {
  
  protected $table;
  
  abstract public function insert();
  abstract public function update($id);
  
  public function find($id) {
      $sql = "SELECT * FROM $this-&gt;table WHERE ID = :id";
      $qry = DB::prepare($sql);
      $qry-&gt;bindParam(':id', $id, PDO::PARAM_INT);
      $qry-&gt;execute();
      return $qry-&gt;fetch();
  }
  
  public function findAll() {
      $sql = "SELECT * FROM $this-&gt;table";
      $qry = DB::prepare($sql);
      $qry-&gt;execute();
      return $qry-&gt;fecthAll();
  }
  
  public function delete($id) {
      $sql = "DELETE FROM $this-&gt;table WHERE ID = :id";
      $qry = DB::prepare($sql);
      $qry-&gt;bindParam(':id', $id, PDO::PARAM_INT);
      return $qry-&gt;execute();
  }
  }
  ?&gt;
  </code></pre>
  
  <p>Then when I try to get any function from the code, I get that message.
  For example, if I try that:</p>
  
  <pre><code>&lt;?php
  
  $crud = new Users();
  $crud-&gt;findAll();
  
  ?&gt;
  </code></pre>
  
  <p>Users.php:</p>
  
  <pre><code>&lt;?php
  
  require_once 'Crud.php';
  
  class Users extends Crud {
  
  protected $table = 'bloggy_user';
  private $username;
  private $email;
  private $password;
  private $passwordRepeat;
  private $nickname;
  private $permission;
  
  public function setUsername($username) {
      $this-&gt;username = $username;
  }
  
  public function setEmail($email) {
      $this-&gt;email    = $email;
  }
  
  public function setPassword($password, $passwordRepeat) {
      if ($password == $passwordRepeat) {
          $cryptedPass    = password_hash($password, PASSWORD_BCRYPT, ['cost' =&gt; 10, 'salt' =&gt; '1234567890123456789011']);
          $this-&gt;password = $cryptedPass;
      }
  }
  
  public function setNickname($nickname) {
      $this-&gt;nickname = $nickname;
  }
  
  public function setPermission($permission) {
      $this-&gt;permission = $permission;
  }
  
  public function checkUsername($username, $email) {
      $sql = "SELECT * FROM $this-&gt;table WHERE username = :username OR email = :email";
      $qry = DB::prepare($sql);
      $qry-&gt;bindParam(':username', $username);
      $qry-&gt;bindParam(':email', $email);
      $qry-&gt;execute();
      if ($qry-&gt;fetchColumn() == 0) {
          return true;
      } else {
          return false;
      }
  }
  
  public function insert() {
      $sql = "INSERT INTO $this-&gt;table (username, email, password, nickname) VALUES (:username, :email, :password, :nickname)";
      $qry = DB::prepare($sql);
      $qry-&gt;bindParam(':username', $this-&gt;username);
      $qry-&gt;bindParam(':email', $this-&gt;email);
      $qry-&gt;bindParam(':password', $this-&gt;password);
      $qry-&gt;bindParam(':nickname', $this-&gt;nickname);
      if ($this-&gt;checkUsername($this-&gt;username, $this-&gt;email)) {
          return $qry-&gt;execute();
      } else {
          echo "Esse usuário já existe";
          return false;
      }
  }
  
  public function update($id) {
      $sql = "UPDATE $this-&gt;table SET email = :email, password = :password, nickname = :nickname, permission = :permission WHERE ID = :id";
      $qry = DB::prepare($sql);
      $qry-&gt;bindParam(':email', $this-&gt;email);
      $qry-&gt;bindParam(':password', $this-&gt;password);
      $qry-&gt;bindParam(':nickname', $this-&gt;nickname);
      $qry-&gt;bindParam(':permission', $this-&gt;permission);
      $qry-&gt;bindParam(':id', $id); 
      return $qry-&gt;execute();
  }
  }
  
  
  ?&gt;
  </code></pre>
  
  <p>It does show the error message.
  Idk if I made myself clear enough, but I'm really a noob at PDO, so if anyone can help me I'd be grateful.</p>