Pdo fetch num problem

hello,
I have a pdo fetch num problem
look at my function here:


function tutofilter_tutorials_get($addon = ''){
      global $tutofilter_db_handle;
      $query = sprintf("SELECT * FROM `tutorials` $addon");
      $qresult = $tutofilter_db_handle->query($query);echo '<br/><pre>'.$query.'</pre><br/>';
      
      if(!$qresult)
          return NULL;
      $rcount = $qresult->fetch(PDO::FETCH_NUM);echo $rcount;
      if($rcount == 0)
          return NULL;
      $tutorials = array();
      for($i = 0;$i < $rcount;$i++)
         $tutorials[count($tutorials)] = $qresult->fetch(PDO::FETCH_OBJ);
      $qresult = NULL;
      return $tutorials;
  }

the fetch num return empty array ,this is the problem
please ,help me.

You need to look at the PHP manual again:

I.e. it doesn’t return the number of rows in a result set.

Heres your code made in a simpler way:

function tutofilter_tutorials_get($addon = ''){
      global $tutofilter_db_handle;
      $query = "SELECT * FROM `tutorials` {$addon}";
      $qresult = $tutofilter_db_handle->query($query);
      if(false === $qresult){
          return null;
      }
      $tutorials = $qresult->fetchAll(PDO::FETCH_OBJ);
      if(empty($tutorials)){
          return null;
      }
      return $tutorials;
}

thank you, mr jake

That’s simply my preferred way of inserting variables into strings. The benefits are outlined here.