PdoDataSource::queryForClass PHP Method

queryForClass() public method

Takes the SQL and arguments (array of Criterion) and returns an array of objects of type $className.
public queryForClass ( SqlBuilder $builder, string $className ) : array($className)
$builder SqlBuilder
$className string the type to fill from query results.
return array($className)
    function queryForClass(SqlBuilder $builder, $className)
    {
        $statement = $this->provider->getStatementForBuilder($builder, 'select', $this);
        $statement->setFetchMode(PDO::FETCH_CLASS, $className, array());
        $statement->execute();
        return $this->provider->fetchAll($statement);
    }

Usage Example

示例#1
0
 /**
  * Once results are needed this method executes the accumulated query
  * on the data source.
  */
 protected function realize()
 {
     if (!$this->hasResults) {
         unset($this->results);
         $this->results = $this->source->queryForClass($this->sqlBuilder, $this->rowClass);
         $this->hasResults = true;
     }
 }