src/Koldy/Db/Model.php
public static function fetch(
      $where,
      array $fields = null,
      string $orderField = null,
      string $orderDirection = null,
      int $limit = null,
      int $start = null
    ): array {
        $select = static::select();

        if ($fields !== null) {
            $select->fields($fields);
        }

        if ($where instanceof Where) {
            $select->where(clone $where);
        } else if (is_array($where)) {
            foreach ($where as $field => $value) {
                $select->where($field, $value);
            }
        } else if (!is_array(static::$primaryKey) && (is_numeric($where) || is_string($where))) {
            $select->where(static::$primaryKey, $where);
        }

        if ($orderField !== null) {
            $select->orderBy($orderField, $orderDirection);
        }

        if ($limit !== null) {
            $select->limit($start ?? 0, $limit);
        }

        $data = [];
        foreach ($select->fetchAll() as $r) {
            $data[] = new static($r);
        }

        return $data;
    }
public static function fetch(
      $where,
      array $fields = null,
      string $orderField = null,
      string $orderDirection = null,
      int $limit = null,
      int $start = null
    ): array {
        $select = static::select();

        if ($fields !== null) {
            $select->fields($fields);
        }

        if ($where instanceof Where) {
            $select->where(clone $where);
        } else if (is_array($where)) {
            foreach ($where as $field => $value) {
                $select->where($field, $value);
            }
        } else if (!is_array(static::$primaryKey) && (is_numeric($where) || is_string($where))) {
            $select->where(static::$primaryKey, $where);
        }

        if ($orderField !== null) {
            $select->orderBy($orderField, $orderDirection);
        }

        if ($limit !== null) {
            $select->limit($start ?? 0, $limit);
        }

        $data = [];
        foreach ($select->fetchAll() as $r) {
            $data[] = new static($r);
        }

        return $data;
    }
public static function fetch ( $ where , array $ fields = null , string $ orderField = null , string $ orderDirection = null , int $ limit = null , int $ start = null ) : array { $ select = static :: select ( ) ; if ( $ fields !== null ) { $ select -> fields ( $ fields ) ; } if ( $ where instanceof Where ) { $ select -> where ( clone $ where ) ; } else if ( is_array ( $ where ) ) { foreach ( $ where as $ field => $ value ) { $ select -> where ( $ field , $ value ) ; } } else if ( ! is_array ( static :: $ primaryKey ) && ( is_numeric ( $ where ) || is_string ( $ where ) ) ) { $ select -> where ( static :: $ primaryKey , $ where ) ; } if ( $ orderField !== null ) { $ select -> orderBy ( $ orderField , $ orderDirection ) ; } if ( $ limit !== null ) { $ select -> limit ( $ start ?? 0 , $ limit ) ; } $ data = [ ] ; foreach ( $ select -> fetchAll ( ) as $ r ) { $ data [ ] = new static ( $ r ) ; } return $ data ; }
Fetch the array of initialized records from database

@param mixed $where the WHERE condition
@param array $fields array of fields to select; by default, all fields will be fetched
@param string|null $orderField
@param string|null $orderDirection
@param int|null $limit

@param int|null $start

@return Model[]

@throws Query\Exception
@throws \Koldy\Exception
@link http://koldy.net/docs/database/models#fetch
Fetch the array of initialized records from database