title: PDO - Call to a member function execute() on a non-object
body: <p>I have a problem with PDO...<br>
  Class, in which i have an error, used for executing select (and in the future - other) queries to database, using PHP:PDO... like that:</p>
  
  <pre><code>$db = new PDOAct;
      $arr    = array("from" =&gt; "users");
      $row    = array("id");
      $val    = array(0);
      $type   = array("INT");
      $db-&gt;select($arr, $row, $val, $type);
  </code></pre>
  
  <p>When i execute this, </p>
  
  <pre><code>&lt;? if (!defined("sKEY")) { exit("Houston, We've Got a Problem"); }
  class PDOAct
  {
      public $db;
      function __construct()
      {
          try {
              $this-&gt;db = new PDO(DBdriver.':host='.DBhost.';dbname='.DBbase, DBuser, DBpass);
              $this-&gt;db-&gt;setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
          } catch(PDOException $e) {
              $this-&gt;err($e-&gt;getMessage());
          }
      }
      function select($arr, $row, $val, $type)
      {
          try {
              for ($i=0; $i&lt;count($row); $i++)
              {
                  if (isset($row[$i]) &amp;&amp; isset($val[$i]) &amp;&amp; isset($type[$i]))
                  {
                      if ($arr[select] != "" &amp;&amp; $arr[select] != "*")
                      {
                          if ($i &lt; 1)
                          {
                              $do = $this-&gt;db-&gt;prepare("SELECT `".$arr[select]."` FROM `".$arr[from]."` WHERE `".$row[$i]."` = ':".$row[$i]."'");
                          } else {
                              $do = $do.$this-&gt;db-&gt;prepare(" AND `".$row[$i]."` = ':".$row[$i]."'");
                          }
                      } elseif ($arr[select] == "" || $arr[select] == "*") {
                          if ($i &lt; 1)
                          {
                              $do = $this-&gt;db-&gt;prepare("SELECT * FROM `".$arr[from]."` WHERE `".$row[$i]."` = ':".$row[$i]."'");
                          } else {
                              $do = $do.$this-&gt;db-&gt;prepare(" AND `".$row[$i]."` = ':".$row[$i]."'");
                          }
                      }
                      $do-&gt;bindValue(':'.$row[$i], $val[$i], "PDO::PARAM_".$type[$i]);
                  } elseif (!isset($row[$i]) &amp;&amp; !isset($val[$i]) &amp;&amp; !isset($type[$i])) {
                      if ($arr[select] != "" &amp;&amp; $arr[select] != "*" &amp;&amp; $i == 0)
                      {
                          $do = $this-&gt;db-&gt;prepare("SELECT `".$arr[select]."` FROM `".$arr[from]."`");
                      } elseif ($arr[select] == "" || $arr[select] == "*" &amp;&amp; $i == 0) {
                          $do = $this-&gt;db-&gt;prepare("SELECT * FROM `".$arr[from]."`");
                      }
                  } else {
                      exit("Query error!");
                  }
              }
              var_dump($this-&gt;db-&gt;prepare("SELECT * FROM `".$arr[from]."` WHERE `".$row[0]."` = ':".$row[0]."'"));
          } catch(PDOException $e) {
              $this-&gt;err($e-&gt;getMessage());
          }
          return $do;
      }
      function err($e)
      {
          file_put_contents('log'.DIR_SEP.'PDOerrors.txt', $e."\n", FILE_APPEND);
          exit("Houston, We've Got a Problem");
      }
  }
  ?&gt;
  </code></pre>
  
  <p>it gives me a php-error: "<strong>Call to a member function execute() on a non-object</strong>"<br>
  I was trying to use <code>var_dump();</code> - it gives me smth like this:<br></p>
  
  <pre><code>object(PDOStatement)#4 (1) { ["queryString"]=&gt; string(40) "SELECT * FROM `users` WHERE `id` = ':id'" }
  </code></pre>
  
  <p>So $this->db->prepare() is <strong>OK</strong>.
  What's the problem? I am suffering about this over 3 hours..<br>
  THANK YOU!</p>