title: PDO Object and Array
body: <p>I have followed PHP Academy's OOP Tutorial over <a href="https://phpacademy.org/videos/oop-loginregister-system" rel="nofollow">here</a></p>
  
  <p>The DB class has been made in a way to fetch database results as an Object</p>
  
  <pre><code>public function query($sql, $params=array()){
      $this-&gt;_error = false;
      if($this-&gt;_query = $this-&gt;_pdo-&gt;prepare($sql)){
          $x=1;
          if(count($params)){
              foreach ($params as $param) {
                  $this-&gt;_query-&gt;bindValue($x, $param);
                  $x++;
              }
          }
  
          if($this-&gt;_query-&gt;execute()){
              $this-&gt;_results = $this-&gt;_query-&gt;fetchAll(PDO::FETCH_OBJ);
              $this-&gt;_count = $this-&gt;_query-&gt;rowCount();
          }else{
              $this-&gt;_error = true;
          }
      }
  
      return $this;
  }
  </code></pre>
  
  <p>This is important cause the user login is done like this</p>
  
  <pre><code>public function login($username = null, $password = null){
  
      $user = $this-&gt;find($username);
  
      if($user){
          if($this-&gt;data()-&gt;password === Hash::make($password, $this-&gt;data()-&gt;salt)){
              Session::put($this-&gt;_sessionName, $this-&gt;data()-&gt;id);
              return true;
          }
      }
      return false;
  }
  </code></pre>
  
  <p>Now when i want to implement foreach to get results row-wise, they are asking for an Array</p>
  
  <pre><code>$result = $product-&gt;getData($_GET['id']);
  if(!empty($result)){
    foreach ($result as $row) {echo $row['id'];}}
  </code></pre>
  
  <p>getData Function</p>
  
  <pre><code>public function getData($_id){
      return $this-&gt;_db-&gt;get('products', array('id', '=', $_id))-&gt;results();
  
  }
  </code></pre>
  
  <p>results function is in DB class</p>
  
  <pre><code>public function results(){
      return $this-&gt;_results;
  }
  </code></pre>
  
  <p>When I change Fetch All to get Both OBJ and ARRAY, User cant log in.</p>
  
  <p>What should i do? Which function to change?</p>
  
  <p>Sorry for Bad English</p>
  
  <p>Thanks in Advance</p>