PDO_MySQL::getAll PHP Method

getAll() public method

返回多行数据
public getAll ( $table, $conditions ) : array
$table string 数据表名
$conditions array 检索条件
return array 返回数据组成的数组
    public function getAll($table, $conditions)
    {
        $fields = empty($conditions['fields']) ? '*' : $conditions['fields'];
        $join = '';
        if (!empty($conditions['join'])) {
            empty($conditions['join']['type']) && ($conditions['join']['type'] = 'join');
            if (in_array(strtolower($conditions['join']['type']), self::$allow_join_type)) {
                $join = $conditions['join']['type'] . " " . $conditions['join']['table'] . " on " . $conditions['join']['on'];
            }
        }
        $where = "";
        if (!empty($conditions['where'])) {
            $tmp_where = self::buildWhere($conditions['where'], $params);
            $where = " where " . implode(' and ', $tmp_where);
        }
        $or_where = "";
        if (!empty($conditions['or_where'])) {
            $tmp_or_where = self::buildWhere($conditions['or_where'], $params);
            $prefix = empty($where) ? " where " : " ";
            $or_where = $prefix . implode(' OR ', $tmp_or_where);
        }
        $group_by = "";
        if (!empty($conditions['group_by'])) {
            $group_by = "GROUP BY " . $conditions['group_by'];
        }
        $having = "";
        if (!empty($conditions['having'])) {
            $tmp_having = self::buildWhere($conditions['having'], $params);
            $having = " HAVING " . implode(' AND ', $tmp_having);
        }
        $sort = "";
        if (!empty($conditions['sort'])) {
            foreach ($conditions['sort'] as $tmp_field => $sort_way) {
                $sort_way = $sort_way == 1 ? " ASC " : " DESC ";
                $tmp_sort[] = $tmp_field . $sort_way;
            }
            $sort = " ORDER BY " . implode(',', $tmp_sort);
        }
        $limit = "";
        if (!empty($conditions['limit'])) {
            $limit = " LIMIT " . intval($conditions['limit']);
        }
        $offset = "";
        if (!empty($conditions['offset'])) {
            $offset = ' OFFSET ' . intval($conditions['offset']);
        }
        $select_sql = implode(" ", array('SELECT', $fields, 'FROM', 'zh_' . $table, $join, $where, $or_where, $group_by, $having, $sort, $limit, $offset));
        $stmt = $this->pdo->prepare($select_sql);
        $this->bind($params, $stmt);
        $result = $stmt->execute();
        if ($result === false) {
            var_dump('select error, args' . json_encode(func_get_args()));
            return false;
        }
        return $stmt->fetchAll(PDO::FETCH_ASSOC);
    }