Doctrine\DBAL\Connection::project PHP Method

project() public method

Executes an, optionally parametrized, SQL query and returns the result, applying a given projection/transformation function on each row of the result.
public project ( string $query, array $params, Closur\Closure $function ) : array
$query string The SQL query to execute.
$params array The parameters, if any.
$function Closur\Closure The transformation function that is applied on each row. The function receives a single parameter, an array, that represents a row of the result set.
return array The projected result of the query.
    public function project($query, array $params, Closure $function)
    {
        $result = array();
        $stmt = $this->executeQuery($query, $params);
        while ($row = $stmt->fetch()) {
            $result[] = $function($row);
        }
        $stmt->closeCursor();
        return $result;
    }