Executes a SELECT query and fetches data from a database.

@param  string $columns
@param  array $where = [] assoc array with format column => value
@param  int $fetch_mode = PDO::FETCH_ASSOC the wished pdo fetch mode
@return DB
357566
public function select(string $columns, array $where = [], int $fetch_mode = PDO::FETCH_ASSOC) : self {
    $this->query_builder->resetProperties();
    $this->query_builder->setMode('select');
    $this->query_builder->setColumns($columns);

    if (!empty($where)) {
      $this->query_builder->setWhere($where);
      $where = $this->formatWhereData($where);
    }

    try {
      $stmt = parent::prepare($this->query_builder->getQuery());
      $stmt->execute($where);
      $this->results = $stmt->fetchAll($fetch_mode);
    } catch (PDOException $e) {
      $this->pdo_exception = $e;
      $this->query_failed = true;
    }

    return $this;
  }
565918
public function delete($table, array $where)
    {
        $query = "DELETE FROM `$table` WHERE ";

        $bind = array();
        foreach ($where as $column => $value) {
            $query .= "`$column` = ? AND ";
            $bind[] = $value;
        }

        $query = substr($query, 0, -5);

        // Prepare, bind and execute
        $statement = $this->prepare($query);
        foreach ($bind as $idx => $value) {
            $statement->bindValue(($idx + 1), $value, Database::typeOfValue($value));
        }

        return $statement->execute();
    }
797896
public function select(array $where = [], array $nosql_options = [])
    {
        // Set statement
        $query = $this->getSelect($where);
        $statement = $this->getInstance()->prepare($query);

        // Bind where values
        foreach ($where as $key => $value) {
            $statement->bindValue(":where_$key", $value, $this->isPdoInt($value));
        }

        // Execute operation
        $statement->execute();

        // Return object
        return $statement->fetchAll(PDO::FETCH_OBJ);
    }
686658
public function sqlFetchColumn(string $sql, array $params = [], string $column = '0')
    {
        return $this->connection()->sqlFetchColumn($sql, $params, $column);
    }
397763
public function queryAll($column = null, $mode = null)
    {
        if (is_null($mode)) {
            $mode = $this->pdo->getAttribute(PDO::ATTR_DEFAULT_FETCH_MODE);
        }

        $result = array();
        $rows = $this->getStmt()->fetchAll($mode);

        if ($column == null) {
            $result = $rows;
        } else {
            foreach ($rows as $row) {
                if (isset($row[$column])) {
                    $result[] = $row[$column];
                } else {
                    return false;
                }
            }
        }

        if ($this->relationProcessor->hasQueue()) {
            return $this->relationProcessor->process($result);
        } else {
            return $result;
        }
    }
1300095
public function executeSelect($tableName, $columns = '*', $where = null, $afterWhere = '')
    {
        return $this->pdo->executeSelect($tableName, $columns, $where, $afterWhere);
    }
715948
public static function all($table,$where=[],$option=[])
    {
        $sql=self::parseSql($table,$where,$option);
        return $sql->fetchAll();
    }
712433
public function fetchColumnAll($sql, array $params=null, $column=0, $offset=0, $length=0)
	{
        if ($length > 0) {
            $sql .= " LIMIT " . (int)$offset . ', '. (int)$length;
        }

		if ($params) {
			$stmt = $this->prepare($sql);
			if (!$stmt) { return false; }

			$flag = $stmt->execute($params);
			if (!$flag) { return false; }
		} else {
			$stmt = $this->query($sql);
			if (!$stmt) { return false; }
		}

		return $stmt->fetchAll(PDO::FETCH_COLUMN, $column);
	}
247601
public function makeSelect(array $columns = null)
    {
        $columns = $columns ?: $this->columns();
        $selects = [];

        foreach ($columns as $key => $select) {
            if (is_int($key)) {
                $selects[] = $select;
            } else {
                $selects[] = DB::raw($select.' as '.$key);
            }
        }

        return $selects;
    }
36823
public function select($columns = [])
    {
        $expr = new ColumnExpression($this->getSQLStatement());

        if ($columns instanceof Closure) {
            $columns($expr);
        } else {
            if (!is_array($columns)) {
                $columns = [$columns];
            }
            $expr->columns($columns);
        }
    }
869364
public function fetchColumn($sql, array $params=null, $column=0)
	{
        $sql .= " LIMIT 1";

		if ($params) {
			$stmt = $this->prepare($sql);
			if (!$stmt) { return false; }

			$flag = $stmt->execute($params);
			if (!$flag) { return false; }
		} else {
			$stmt = $this->query($sql);
			if (!$stmt) { return false; }
		}

		return $stmt->fetchColumn($column);
	}
264582
public function sqlFetchAllColumn(string $sql, array $params = [], string $column = '0'): array
    {
        return $this->connection()->sqlFetchAllColumn($sql, $params, $column);
    }
414791
protected function select($columns=[])
    {
        $query = $this->model->newQuery()->getQuery();
        if ($columns) {
            $query->select($columns);
        }
        return $query;
    }
963236
public function select($cols = null, $where = true, $order = null, $limit = null)
    {
        if ($this->map) {
            $cols = $this->map->cols($cols);
            $where = $this->map->where($where);
            $order = $this->map->order($order);
        }
        if ($cols === null) {
            $cols = true;
        }
        if ($this->fake) {
            $result = $this->fake->select($cols, $where, $order, $limit);
            if ($this->map) {
                return new ArrFetcher($this->map->assoc($result));
            }
            return $result;
        }
        $pattern = 'SELECT ?cols FROM ?t WHERE ?w';
        $data = array($cols, $this->name, $where);
        if ($order !== null) {
            $pattern .= ' ORDER BY ?o';
            $data[] = $order;
        }
        if ($limit !== null) {
            if (is_array($limit)) {
                $offset = isset($limit[1]) ? $limit[1] : 0;
                $limit = $limit[0];
            } else {
                $offset = 0;
            }
            $pattern .= ' LIMIT ?i,?i';
            $data[] = $offset;
            $data[] = $limit;
        }
        $fetcher = $this->db->query($pattern, $data);
        if ($this->map) {
            $data = $fetcher->assoc();
            $data = $this->map->assoc($data);
            $fetcher = new ArrFetcher($data);
        }
        return $fetcher;
    }
820226
public function query($query = '', $params = null, $fetchmode = PDO::FETCH_ASSOC)
    {
        $query = trim($query);
        if (empty($query)) {
            $query = $this->build();
            if (!$params) {
                $params = $this->getBindValues();
            }
        }

        $this->resetAll();
        $this->lastSql = $query;

        $this->execute($query, $params);

        $rawStatement = explode(" ", $query);

        $statement = strtolower(trim($rawStatement[0]));
        if ($statement === 'select' || $statement === 'show') {
            return $this->sQuery->fetchAll($fetchmode);
        } elseif ($statement === 'update' || $statement === 'delete') {
            return $this->sQuery->rowCount();
        } elseif ($statement === 'insert') {
            if ($this->sQuery->rowCount() > 0) {
                return $this->lastInsertId();
            }
        } else {
            return null;
        }

        return null;
    }
899397
public function select($tableName, $where = null, $afterWhere = '')
    {
        $stmt = $this->executeSelect($tableName, '*', $where, $afterWhere);
        return $stmt->fetchAll(PDO::FETCH_ASSOC);
    }
483162
public function selectValue($tableName, $column, $where = null)
    {
        $stmt = $this->executeSelect($tableName, $column, $where);
        return $stmt->fetchColumn();
    }