title: PHP PDO: Call to a member function fetch() on boolean
body: <p>So I'm currently trying to do a PDO SELECT Request, but when executing and fetching the extracted data, this error shows up:</p>
  
  <pre><code>1 - Fatal error: Uncaught Error: Call to a member function fetch() on boolean in C:\wamp64\www\NewKali\includes\user.inc.php on line 53    
  2 - Error: Call to a member function fetch() on boolean in C:\wamp64\www\NewKali\includes\user.inc.php on line 53
  </code></pre>
  
  <p><strong><em>This is where I call the function:</em></strong></p>
  
  <pre><code>include 'includes/user.inc.php';
  $userOBJ = new User;
  if($userOBJ-&gt;isAdmin($_SESSION['session_u-name'])){
      AdminControl();
  }
  </code></pre>
  
  <p><strong><em>Code:</em></strong></p>
  
  <pre><code>public function isAdmin($user){
      $userToGet = $user;
  
      $stmt = $this-&gt;Connect()-&gt;prepare("SELECT * FROM user_secure WHERE username_db=?");
      $query1 = $stmt-&gt;execute([$userToGet]);
  
      if(!$query1)
      {
        die("Execute query error, because: ". print_r($this-&gt;Connect()-&gt;errorInfo(),true) );
      }else{
           foreach ($query1-&gt;fetch() as $row) {
               if($row['admin_db'] == 1){
                  return true;
               } else {
                  return false;
               }
           }
      }
  }
  </code></pre>
  
  <p>The first error says that I'm not handling the PDO errors, which I think that I'm already handling any PDO error in my code, but somehow still gets detected as I'm not doing so... (Correct me if wrong)</p>
  
  <p>Second error states that calling PDO->fetch() is returning a boolean, but I'm requesting data, so it's not able to continue with the following code... 
  I don't get why this is showing... The "username_db" var in the query is the same as the one that I have in my DB.</p>
  
  <p><strong>In the same file as the function above, I have this next function and when called, it does fine</strong></p>
  
  <pre><code>public function RegisterUser($user, $pwd, $mail){
      $u_Insert = $user;
      $p_Insert = $pwd;
      $m_Insert = $mail;
  
      $stmt = $this-&gt;Connect()-&gt;prepare("INSERT INTO user_secure(username_db, password_db) VALUES (?,?)");
      $query1 = $stmt-&gt;execute([$u_Insert, $p_Insert]);
  
      $stmt = $this-&gt;Connect()-&gt;prepare("INSERT INTO user_info(mail_db) VALUES (?)");
      $query2 = $stmt-&gt;execute([$m_Insert]);
  
      if($query2 &amp;&amp; $query1){
          return true;
      } else {
          return false;
      }
  }
  </code></pre>
  
  <p>Is there something that I'm missing?
  I have already checked this <a href="https://stackoverflow.com/questions/32696192/call-to-a-member-function-fetch-on-boolean">thread</a> but I'm still in the exact position... </p>
  
  <p><strong><em>Thank you for your time</em></strong></p>
  
  <p>(I'm still learning PDO, sorry if my code isn't clean)</p>