SelectQuery::fetchAll PHP Method

fetchAll() public method

Fetch all row
public fetchAll ( string $index = '', string $selectOnly = '' ) : array
$index string specify index column
$selectOnly string select columns which could be fetched
return array of fetched rows
    public function fetchAll($index = '', $selectOnly = '')
    {
        if ($selectOnly) {
            $this->select(null)->select($index . ', ' . $selectOnly);
        }
        if ($index) {
            $data = array();
            foreach ($this as $row) {
                if (is_object($row)) {
                    $data[$row->{$index}] = $row;
                } else {
                    $data[$row[$index]] = $row;
                }
            }
            return $data;
        } else {
            if (($s = $this->execute()) !== false) {
                if ($this->convertTypes) {
                    return FluentUtils::convertToNativeTypes($s, $s->fetchAll());
                } else {
                    return $s->fetchAll();
                }
            }
            return $s;
        }
    }

Usage Example

Exemplo n.º 1
0
 public static function search(TableCtl $controller, $term, $filter = false)
 {
     $object = call_user_func(array(get_class($controller), 'getObject'));
     if (!$object) {
         return false;
     }
     $terms = preg_split('/[ ,]/', $term);
     if (!count($terms)) {
         return false;
     }
     //Check for results containing the word
     $search = array();
     foreach ($terms as $oneTerm) {
         $search[] = '`word` LIKE CONCAT("%", ?, "%")';
     }
     //Check for results with the exact word
     $search[] = '`word` IN (' . implode(', ', array_fill(0, count($terms), '?')) . ')';
     $search = '(' . implode(') OR (', $search) . ')';
     $params = array_merge(array($object->getSource()), $terms, $terms);
     $query = new SelectQuery(get_called_class());
     $query->field('DISTINCT `' . $object->getMeta('table') . '`.*')->leftJoin(get_class($controller), '`' . $object->getMeta('table') . '`.`' . $object->getMeta('id_field') . '` = `table_id`')->filter('`table` = ?')->filter($search)->order('`count` DESC, `sequence`');
     if ($filter) {
         if (is_array($filter)) {
             foreach ($filter as $one_fil) {
                 $query->filter($one_fil);
             }
         } else {
             $query->filter($filter);
         }
     }
     $result = $query->fetchAll($params);
     return $result;
 }
All Usage Examples Of SelectQuery::fetchAll