title: PHP Fatal error: Call to a member function prepare() on a non-object in
body: <pre><code>Fatal error: Call to a member function prepare() on a non-object in 
  /home/addictiv/public_html/AddictiveRP/Online/lib/katniss/mod.DB.php on line 95
  </code></pre>
  
  <p>This is mod.DB.php    </p>
  
  <p>
  
  <pre><code>class DB
  {
      static $db = null;
      static $queries = 0;
      static $ms = 0;
  
      //
      // Connect to a PDO database
      //
      static function Connect( $connectstr, $username, $password, $persistant = false, $throwerror = true, $debug = false )
      {
          DEBUG::Msg( "Connecting to database", 'db' );
  
          $time = microtime( true );
  
          $options = array(
              PDO::ATTR_PERSISTENT =&gt; $persistant
          );
  
          try 
          {
              DB::$db = @new PDO( $connectstr, $username, $password, $options );
  
              if( $debug )
                  DB::$db-&gt;setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
          } 
          catch ( exception $e )
          {
              DEBUG::Msg( "Connection Failed!", 'db' );
  
              if ( $throwerror )
                  DEBUG::Error( array( 'error' =&gt; "Failed to connect", 'message' =&gt; $e-&gt;getMessage() ), 'DB' );
  
              return false;
          }
  
          DB::$ms +=  microtime( true ) - $time;
  
          DEBUG::Msg( "Connected!", 'db' );
  
          return true;
      }
  
      //
      // Throws an error if the database isn't ready
      //
      static function Check()
      {
          if ( !DB::$db )
              DEBUG::Error( array( 'error' =&gt; "No Connection" ), 'DB' );
      }
  
      //
      // Prepared statement wrapper
      //
      static function Query( $str, $arry = null )
      {
          DB::Check();
          DB::$queries++;
  
          DEBUG::Msg( "Query Start:", 'db' );
          DEBUG::Msg( $str, 'db' );
  
          $time = microtime( true );
  
          $st = DB::$db-&gt;prepare( $str );       // Line 95 error
  
          if ( !$st )
              DEBUG::Error( array( 'error' =&gt; "Create Query Failed", 'query' =&gt; $str, 'array' =&gt; $arry, 'message' =&gt; DB::$db-&gt;errorInfo() ), 'DB' );
  
          if ( !$st-&gt;execute( $arry ) )
              DEBUG::Error( array( 'error' =&gt; "Query Failed", 'query' =&gt; $str, 'array' =&gt; $arry, 'message' =&gt; $st-&gt;errorInfo()), 'DB' );
  
          $result = $st-&gt;fetchAll( PDO::FETCH_ASSOC );    
  
          DEBUG::Msg( "Done", 'db' );
  
          DB::$ms +=  microtime( true ) - $time;
  
  
          return $result;
      }
  
      static function QueryRow( $str, $arry = null ) { $ret = DB::Query( $str, $arry ); if ( $ret ) return reset( $ret ); }
      static function QueryValue( $str, $arry = null ) { $ret = DB::QueryRow( $str, $arry ); if ( $ret ) return reset( $ret ); }
  
      static function QueryUpdateCheck($str, $arry = null){
          DB::Check();
          DB::$queries++;
  
          DEBUG::Msg( "Query Start:", 'db' );
          DEBUG::Msg( $str, 'db' );
  
          $time = microtime( true );
  
          $st = DB::$db-&gt;prepare( $str );
  
          if ( !$st )
              DEBUG::Error( array( 'error' =&gt; "Create Query Failed", 'query' =&gt; $str, 'array' =&gt; $arry, 'message' =&gt; DB::$db-&gt;errorInfo() ), 'DB' );
  
          if ( !$st-&gt;execute( $arry ) )
              DEBUG::Error( array( 'error' =&gt; "Query Failed", 'query' =&gt; $str, 'array' =&gt; $arry, 'message' =&gt; $st-&gt;errorInfo()), 'DB' );
  
          $st;
  
          DEBUG::Msg( "Done", 'db' );
  
          DB::$ms +=  microtime( true ) - $time;
  
          return $st-&gt;rowCount();
  
  
  
  
      }
  
      //
      // Insert an array into the database. Returns the insert id
      //
      static function Insert( $table, $arry, $insert = "INSERT" ) 
      {       
          $keys       = array();
          $keys_val   = array();
          $values     = array();
  
          foreach ( $arry as $k =&gt; $v )
          {
              $keys[]             = $k;
              $keys_val[]         = ':'.$k;
              $values[':'.$k]     = $v;
          }
  
          $query = $insert . " INTO " . $table . " (".implode( ',', $keys ).") VALUES ( ".implode( ',', $keys_val )." )";
  
  
          DB::Check();
          DB::$queries++;
  
          DEBUG::Msg( "Insert Start: [".$query."]", 'db' );
  
          $time = microtime( true );
  
          $st = DB::$db-&gt;prepare( $query );
  
          if ( !$st )
              DEBUG::Error( array( 'error' =&gt; "Create Insert Failed", 'query' =&gt; $query, 'array' =&gt; $values, 'message' =&gt; DB::$db-&gt;errorInfo() ), 'DB' );
  
          if ( !$st-&gt;execute( $arry ) )
              DEBUG::Error( array( 'error' =&gt; "Insert Failed", 'query' =&gt; $query, 'array' =&gt; $values, 'message' =&gt; $st-&gt;errorInfo()), 'DB' );
  
          DEBUG::Msg( "Done", 'db' );
  
          DB::$ms +=  microtime( true ) - $time;
  
          return DB::$db-&gt;lastInsertId();
      }
  
      //
      // Like insert, but replaces the entry if it exists.
      //
      static function Replace( $table, $arry ) 
      {
          return DB::Insert( $table, $arry, 'REPLACE' );
      }
  
      //
      // Called when shutting down
      //
      static function OnShutdown()
      {
          DEBUG::Msg( "Database: ". DB::$queries . " queries (". round( DB::$ms, 3 ) . " seconds)", 'db'  );
      }
  
  }
  </code></pre>
  
  <p>What it calls for:</p>
  
  <pre><code>&lt;?php
                  define('MySQLSet', true); // Change this to true once you've entered your MySQL settings below
                  define('MySQLHost', ''); // The host of your MySQL database.
                  define('MySQLDBName', ''); // The name of your MySQL database.
                  define('MySQLDBUName', ''); // The username of your MySQL database;
                  define('MySQLDBPassword', ''); // The password of the user.
                  define('PAGEID', '2003'); // Your VXDonation page id.
                  define('APIKEY', ''); // Your Steam API Key (For avatars and such)
                  define('BaseURL', '/Online/'); // Where the system is installed relative to your root.
                  define('CURSYMBOL', '$'); // The symbol of your real world currency. £ or $ or whatever.
                  // For example, if you accessed the system by going to yoursite.com/donation/mydonation,
  </code></pre>
  
  <p>I'm not an expert at this at all so i have no idea what's wrong </p>