title: Fatal error: Call to a member function execute() on null
body: <p>I keep getting the following error:</p>
  
  <blockquote>
    <p><strong>Fatal error:</strong> Call to a member function execute() on null in /home/<strong><em>[sitename]</em></strong>/public_html/fc/includes/class_db_handle.php on line 130</p>
  </blockquote>
  
  <p>This is from the u-Auctions script and I honestly am extremely noob to PDO
  please help in "DUMMIE TERMS".</p>
  
  <pre><code>if (!defined('InuAuctions')) exit('Access denied');
  
  class db_handle 
  
  {
  
      // database
  
      private     $pdo;
  
      private     $DBPrefix;
  
      private     $CHARSET;
  
      private     $lastquery;
  
      private     $fetchquery;
  
      private     $error;
  
      public      $PDOerror;
  
  
  
      public function connect($DbHost, $DbUser, $DbPassword, $DbDatabase, $DBPrefix, $CHARSET)
  
      {
  
          $this-&gt;DBPrefix = $DBPrefix;
  
          $this-&gt;CHARSET = $CHARSET;
  
          try {
  
              // MySQL with PDO_MYSQL
  
              $this-&gt;pdo = new PDO("mysql:host=$DbHost;dbname=$DbDatabase;charset =$CHARSET", $DbUser, $DbPassword);
  
  
              // set error reporting up
  
              $this-&gt;pdo-&gt;setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  
              // actually use prepared statements
  
              $this-&gt;pdo-&gt;setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
  
          }
  
          catch(PDOException $e) {
  
              $this-&gt;trigger_error($e-&gt;getMessage());
  
          }
  
      }
  
  
  
      // to run a direct query
  
      public function direct_query($query)
  
      {
  
          try {
  
              $this-&gt;lastquery = $this-&gt;pdo-&gt;query($query);
  
          }
  
          catch(PDOException $e) {
  
              $this-&gt;trigger_error($e-&gt;getMessage());
  
          }
  
      }
  
  
  
      // put together the quert ready for running
  
      /*
  
      $query must be given like SELECT * FROM table WHERE this = :that AND where = :here
  
      then $params would holds the values for :that and :here, $table would hold the vlue for :table
  
      $params = array(
  
          array(':that', 'that value', PDO::PARAM_STR),
  
          array(':here', 'here value', PDO::PARAM_INT),
  
      );
  
      last value can be left blank more info http://php.net/manual/en/pdostatement.bindparam.php
  
      */
  
      public function query($query, $params = array())
  
      {
  
          try {
  
              //$query = $this-&gt;build_query($query, $table);
  
              $params = $this-&gt;build_params($params);
  
              $params = $this-&gt;clean_params($query, $params);
  
              $this-&gt;lastquery = $this-&gt;pdo-&gt;prepare($query);
  
              //$this-&gt;lastquery-&gt;bindParam(':table', $this-&gt;DBPrefix . $table, PDO::PARAM_STR); // must always be set
  
              foreach ($params as $val)
  
              {
  
                  $this-&gt;lastquery-&gt;bindParam($val[0], $val[1], @$val[2], @$val[3], @$val[4]);
  
              }
  
              $this-&gt;lasta-&gt;execute();
  
              //$this-&gt;lastquery-&gt;debugDumpParams();
  
          }
  
          catch(PDOException $e) {
  
              //$this-&gt;lastquery-&gt;debugDumpParams();
  
              $this-&gt;trigger_error($e-&gt;getMessage());
  
          }
  
  
  
          //$this-&gt;lastquery-&gt;rowCount(); // rows affected
  
      }
  
  
  
      // put together the quert ready for running
  
      public function fetch($method = 'FETCH_ASSOC')
  
      {
  
          try {
  
              // set fetchquery
  
              if ($this-&gt;fetchquery == NULL)
  
              {
  
                  $this-&gt;fetchquery = $this-&gt;lastquery;
  
              }
  
              if ($method == 'FETCH_ASSOC') $result = $this-&gt;fetchquery-&gt;fetch(PDO::FETCH_ASSOC);
  
              if ($method == 'FETCH_BOTH') $result = $this-&gt;fetchquery-&gt;fetch(PDO::FETCH_BOTH);
  
              if ($method == 'FETCH_NUM') $result = $this-&gt;fetchquery-&gt;fetch(PDO::FETCH_NUM);
  
              // clear fetch query
  
              if ($result == false)
  
              {
  
                  $this-&gt;fetchquery = NULL;
  
              }
  
              return $result;
  
          }
  
          catch(PDOException $e) {
  
              $this-&gt;trigger_error($e-&gt;getMessage());
  
          }
  
      }
  
  
  
      // put together the quert ready for running + get all results
  
      public function fetchall($method = 'FETCH_ASSOC')
  
      {
  
          try {
  
              // set fetchquery
  
              if ($this-&gt;fetchquery == NULL)
  
              {
  
                  $this-&gt;fetchquery = $this-&gt;lastquery;
  
              }
  
              if ($method == 'FETCH_ASSOC') $result = $this-&gt;fetchquery-&gt;fetchAll(PDO::FETCH_ASSOC);
  
              if ($method == 'FETCH_BOTH') $result = $this-&gt;fetchquery-&gt;fetchAll(PDO::FETCH_BOTH);
  
              if ($method == 'FETCH_NUM') $result = $this-&gt;fetchquery-&gt;fetchAll(PDO::FETCH_NUM);
  
              // clear fetch query
  
              if ($result == false)
  
              {
  
                  $this-&gt;fetchquery = NULL;
  
              }
  
              return $result;
  
          }
  
          catch(PDOException $e) {
  
              $this-&gt;trigger_error($e-&gt;getMessage());
  
          }
  
      }
  
  
  
      public function result($column = NULL)
  
      {
  
          $data = $this-&gt;lastquery-&gt;fetch(PDO::FETCH_BOTH);
  
          if (empty($column) || $column == NULL)
  
          {
  
              return $data;
  
          }
  
          else
  
          {
  
              return $data[$column];
  
          }
  
      }
  
  
  
      public function numrows()
  
      {
  
          try {
  
              return $this-&gt;lastquery-&gt;rowCount();
  
          }
  
          catch(PDOException $e) {
  
              $this-&gt;trigger_error($e-&gt;getMessage());
  
          }
  
      }
  
  
  
      public function lastInsertId()
  
      {
  
          try {
  
              return $this-&gt;pdo-&gt;lastInsertId();
  
          }
  
          catch(PDOException $e) {
  
              $this-&gt;trigger_error($e-&gt;getMessage());
  
          }
  
      }
  
  
  
      private function clean_params($query, $params)
  
      {
  
          // find the vars set in the query
  
          preg_match_all("(:[a-zA-Z_]+)", $query, $set_params);
  
          //print_r("params" . $query);
  
          //print_r($params);
  
          //print_r("set_params");
  
          //print_r($set_params);
  
          $new_params = array();
  
          foreach ($set_params[0] as $val)
  
          {
  
              $key = $this-&gt;find_key($params, $val);
  
              $new_params[] = $params[$key];
  
          }
  
          //print_r("new_params");
  
          //print_r($new_params);
  
          return $new_params;
  
      }
  
  
  
      private function find_key($params, $val)
  
      {
  
          foreach ($params as $k =&gt; $v)
  
          {
  
              if ($v[0] == $val)
  
                  return $k;
  
          }
  
      }
  
  
  
      private function build_params($params)
  
      {
  
          $PDO_constants = array(
  
              'int' =&gt; PDO::PARAM_INT,
  
              'str' =&gt; PDO::PARAM_STR,
  
              'bool' =&gt; PDO::PARAM_BOOL,
  
              'float' =&gt; PDO::PARAM_STR
  
              );
  
          // set PDO values to params
  
          for ($i = 0; $i &lt; count($params); $i++)
  
          {
  
              // force float
  
              if ($params[$i][2] == 'float')
  
              {
  
                  $params[$i][1] = floatval($params[$i][1]);
  
              }
  
              $params[$i][2] = $PDO_constants[$params[$i][2]];
  
          }
  
          return $params;
  
      }
  
  
  
      private function trigger_error($error)
  
      {
  
  
  
          // DO SOMETHING
  
          //$this-&gt;error = $error;
  
          $this-&gt;PDOerror = $error;
  
      }
  
  
  
      // close everything down
  
      public function __destruct()
  
      {
  
          // close database connection
  
          $this-&gt;pdo = null;
  
      }
  
  }
  </code></pre>