title: How to check if query return no result in PDO
body: <p>I'm pretty sure this question have been asked a lot by community, but i haven't found any good answer.</p>
  
  <p>i have this code :</p>
  
  <pre><code>$keyword = '%'.strtoupper($_POST['keyword']).'%';
  $limitMaterial = 'AS-%';
  $findMaterial = $oracle-&gt;prepare('SELECT inventory_item_id, segment1, description, inventory_item_status_code FROM mtl_system_items_b WHERE segment1 LIKE ? AND (segment1 LIKE ? OR description LIKE ?)');
  $findMaterial-&gt;bindParam(1, $limitMaterial, PDO::PARAM_STR);
  $findMaterial-&gt;bindParam(2, $keyword, PDO::PARAM_STR);
  $findMaterial-&gt;bindParam(3, $keyword, PDO::PARAM_STR);
  $findMaterial-&gt;execute();
  $checkRow = $findMaterial-&gt;fetch(PDO::FETCH_ASSOC);
  
  $boldKeyword = '&lt;font color="red"&gt;&lt;b&gt;' . $keyword . '&lt;/b&gt;&lt;/font&gt;';
  
  if($checkRow !== false){
      var_dump($checkRow); // this is for testing only
      foreach($findMaterial as $dataMaterial){
          var_dump($dataMaterial); // this is for testing only
          $dataMaterial = array_change_key_case($dataMaterial,CASE_LOWER);
          $code = str_ireplace($keyword,$boldKeyword,$dataMaterial['segment1']);
          $desc = str_ireplace($keyword,$boldKeyword,$dataMaterial['description']);
          if(isset($_POST['idf'])){
              $idf = $_POST['idf'];
              echo '&lt;div class="show" align="left" onclick="select('.$idf.',this); return false;"&gt;&lt;span&gt;'.$code.'&lt;/span&gt;&lt;span style="visibility: hidden; font-size:1px;" class="find_material_'.$idf.'"&gt;'.$dataMaterial['segment1'].'&lt;/span&gt;&lt;/br&gt;'.$desc.'&lt;/div&gt;'; 
          } else {
              echo '&lt;div class="show" align="left"&gt;&lt;span&gt;'.$code.'&lt;/span&gt;&lt;span style="visibility: hidden; font-size:1px;" class="basic_code"&gt;'.$dataMaterial['segment1'].'&lt;/span&gt;&lt;/br&gt;'.$desc.'&lt;/div&gt;'; 
          }
      }
  } else {
      echo '&lt;div class="show" align="left"&gt;Part Code Not Found&lt;/div&gt;'; 
  }
  
  $findMaterial = null;
  </code></pre>
  
  <p>What i want to ask is, <em>how to check if my query returned a result or not?</em>. My current code is working, but i have an issue that this line :</p>
  
  <pre><code>$checkRow = $findMaterial-&gt;fetch(PDO::FETCH_ASSOC);
  </code></pre>
  
  <p>Take 1 row from results, so i'm missing 1 row in foreach loop. I've tried fetchColumn() (where it have same issue), and rowCount() (where it return 0 for SELECT statement).</p>
  
  <p>If possible i want to avoid using "SELECT COUNT(1) FROM [table]" to check if data exist, or doing what happen in foreach loop outside it just for that 1 row.</p>
  
  <p>Any help is appreciated. Thank you</p>