src/Service/DB/Select.php
public function compile()
    {
        $adapter = $this->adapter;
        $sql = 'SELECT ';
        $params = [];

        $sql .= $this->columns
              ? implode(', ', $adapter->quoteIdentifier($this->columns))
              : '*';

        list($table, $table_params) = $this->compileFrom();
        if ($table_params) {
            $params = array_merge($params, $table_params);
        }

        $sql .= ' FROM ' . $table;

        list($where, $where_params) = $this->compileWhere();
        if ($where) {
            $sql .= ' WHERE ' . $where;
        }

        if ($where_params) {
            $params = array_merge($params, $where_params);
        }

        list($group_by, $group_params) = $this->compileGroupBy();
        if ($group_by) {
            $sql .= ' ' . $group_by;
        }

        if ($group_params) {
            $params = array_merge($params, $group_params);
        }

        if ($this->order_by) {
            $sql .= ' ORDER BY ' . implode(', ', $this->order_by);
        }

        if ($this->limit) {
            $sql .= ' LIMIT ' . $this->limit;
        }

        if ($this->offset) {
            $sql .= ' OFFSET ' . $this->offset;
        }

        return [$sql, $params];
    }
public function compile()
    {
        $adapter = $this->adapter;
        $sql = 'SELECT ';
        $params = [];

        $sql .= $this->columns
              ? implode(', ', $adapter->quoteIdentifier($this->columns))
              : '*';

        list($table, $table_params) = $this->compileFrom();
        if ($table_params) {
            $params = array_merge($params, $table_params);
        }

        $sql .= ' FROM ' . $table;

        list($where, $where_params) = $this->compileWhere();
        if ($where) {
            $sql .= ' WHERE ' . $where;
        }

        if ($where_params) {
            $params = array_merge($params, $where_params);
        }

        list($group_by, $group_params) = $this->compileGroupBy();
        if ($group_by) {
            $sql .= ' ' . $group_by;
        }

        if ($group_params) {
            $params = array_merge($params, $group_params);
        }

        if ($this->order_by) {
            $sql .= ' ORDER BY ' . implode(', ', $this->order_by);
        }

        if ($this->limit) {
            $sql .= ' LIMIT ' . $this->limit;
        }

        if ($this->offset) {
            $sql .= ' OFFSET ' . $this->offset;
        }

        return [$sql, $params];
    }
根据当前查询对象的各项参数，编译为具体的select语句及查询参数.

@return
array(
(string),    // select语句
(array)      // 查询参数值
)