Cml\Db\MySql\Pdo::select PHP Метод

select() публичный Метод

获取多条数据
public select ( integer $offset = null, integer $limit = null, boolean $useMaster = false ) : array
$offset integer 偏移量
$limit integer 返回的条数
$useMaster boolean 是否使用主库 默认读取从库
Результат array
    public function select($offset = null, $limit = null, $useMaster = false)
    {
        is_null($offset) || $this->limit($offset, $limit);
        $this->sql['columns'] == '' && ($this->sql['columns'] = '*');
        $columns = $this->sql['columns'];
        $table = $operator = $cacheKey = '';
        foreach ($this->table as $key => $val) {
            $realTable = $this->getRealTableName($key);
            $cacheKey .= $this->getCacheVer($realTable);
            $on = null;
            if (isset($this->join[$key])) {
                $operator = ' INNER JOIN';
                $on = $this->join[$key];
            } elseif (isset($this->leftJoin[$key])) {
                $operator = ' LEFT JOIN';
                $on = $this->leftJoin[$key];
            } elseif (isset($this->rightJoin[$key])) {
                $operator = ' RIGHT JOIN';
                $on = $this->rightJoin[$key];
            } else {
                empty($table) || ($operator = ' ,');
            }
            if (is_null($val)) {
                $table .= "{$operator} `{$realTable}`";
            } else {
                $table .= "{$operator} `{$realTable}` AS `{$val}`";
            }
            is_null($on) || ($table .= " ON {$on}");
        }
        if (empty($table)) {
            throw new \InvalidArgumentException(Lang::get('_PARSE_SQL_ERROR_NO_TABLE_', 'select'));
        }
        empty($this->sql['limit']) && ($this->sql['limit'] = "LIMIT 0, 100");
        $sql = "SELECT {$columns} FROM {$table} " . $this->sql['where'] . $this->sql['groupBy'] . $this->sql['having'] . $this->sql['orderBy'] . $this->union . $this->sql['limit'];
        $cacheKey = md5($sql . json_encode($this->bindParams)) . $cacheKey;
        $return = Model::getInstance()->cache()->get($cacheKey);
        if ($return === false) {
            $stmt = $this->prepare($sql, $useMaster ? $this->wlink : $this->rlink);
            $this->execute($stmt);
            $return = $stmt->fetchAll(\PDO::FETCH_ASSOC);
            Model::getInstance()->cache()->set($cacheKey, $return, $this->conf['cache_expire']);
        } else {
            if (Cml::$debug) {
                $this->currentSql = $sql;
                $this->debugLogSql(Debug::SQL_TYPE_FROM_CACHE);
                $this->currentSql = '';
            }
            $this->reset();
            $this->clearBindParams();
        }
        return $return;
    }