@param string $tableName
@param string $where
@param string $order
@param string $limit

@return array
168584
public function cuSelectAsArray($tableName, $where = '', $order = '', $limit = '')
    {

        $data_array = [];
        $where      = trim($where);
        $order      = trim($order);
        $limit      = trim($limit);
        if ($where === false) {
            $where = '';
        }
        if ($where !== '') {
            $where = ' WHERE ' . $where;
        }
        if ($order !== '') {
            $order = ' ORDER BY ' . $order;
        }
        if ($limit !== '') {
            $limit = ' LIMIT ' . $limit;
        }

        /** @noinspection SqlNoDataSourceInspection */
        $q      = 'SELECT * FROM `%s` %s %s %s;';
        $q      = sprintf($q, $tableName, $where, $order, $limit);
        $result = $this->query($q);

        if ($result !== false) {
            while ($data = $result->fetch_assoc()) {
                $data_array[] = $data;
            }
        }

        return $data_array;
    }
32241
public function find($table, $fields = null, $where = null, $order = null, $limit = null, $offset = null, $array = array(), $fetchMode = \PDO::FETCH_ASSOC)
     {
         $sql = ' SELECT '.(($fields) ?? '*').' FROM '.(($table)).(($where) ? ' WHERE '.$where : ' ')
            .(($limit) ? ' LIMIT '.$limit : ' ')
            .(($offset && $limit) ? ' OFFSET '.$offset : ' ')
            .(($order) ? ' ORDER BY '.$order : ' ');

         $stmt = $this->conn->prepare($sql);

         foreach ($array as $key => $values) {
             return  $stmt->bindValue("$key", $values);
         }
         $stmt->execute();

         do {
             return $stmt->fetchAll($fetchMode);
         } while (
            $stmt->nextRowset());
         $stmt->close();
     }
140985
public function getData( $first = FALSE, $orders = array(), $limit = array(), $verbose = FALSE )
	{
		$data = array();
		if( $this->isFocused() && sizeof( $this->fields ) )
		{
			$conditions	= $this->getConditionQuery( array() );
			$orders		= $this->getOrderQuery( $orders );
			$limit		= $this->getLimitQuery( $limit );

		 	$query = 'SELECT * FROM '.$this->getTableName().' WHERE '.$conditions.$orders.$limit;
			if( $verbose )
				echo '<br/>'.$query;
			$q	= $this->dbc->Execute( $query );
			if( $q->RecordCount() )
			{
				while( $d = $q->FetchNextObject( FALSE ) )
				{
					$line = array();
					foreach( $this->fields as $field )
						$line[$field] = $d->$field;
					$data[] = $line;
				}
			}
		}
		if( count( $data ) && $first )
			$data	= $data[0];
		return $data;
	}
418982
public static function findColumns (array $columns, int $limit=0, string $order="DESC")
	{
		$order 	   	= static::validateOrder($order);
        $dbObject  	= Database::getInstance();
		$columns 	= joinArray($dbObject->escapeValues($columns), ', ');
		return static::limitFindBySql("SELECT {$columns} FROM ".static::$tableName." ORDER BY id {$order}", $limit);
	}
1333109
public function selectArray($fields = null, $where = null, $orderBy = null, $limit = null): array
    {
        return self::select2($fields, $where, $orderBy, $limit);
    }
506524
public function getEntitiesBy(array $criteria = [], array $orders = [], $limit = null, $offset = null): array
    {
        $entities = $this->getRepository()->findBy($criteria, $orders, $limit, $offset);
        $this->prepareEntitesForGet($entities);

        return $entities;
    }
680340
public function selectAll($limit = 0)
	{
		$stmt = $this->pdo->prepare(<<<EOT
SELECT 
	t1.*,
	t2.ProjectId AS "Project.ProjectId",
	t2.Name AS "Project.Name",
	t2.Description AS "Project.Description",
	t2.Created AS "Project.Created"   
FROM `$this->tableName` AS t1 
LEFT JOIN Projects AS t2 ON t1.ProjectId = t2.ProjectId 
ORDER BY t1.Started DESC ;
EOT
		);
		$res = $stmt->execute();

		if ($res === false) {
			return array();
		}

		$rows = $stmt->fetchAll();

		$ret = array();
		foreach ($rows as $row) {
			array_push($ret, $this->prepareEntity($row));
		}

		return $ret;
	}
1187263
public function update($table, $data, $where, $limit = null)
    {
        $query = $this->provider->buildUpdateQuery($table, $data, $where, $limit);

        return $this->provider->query($query, null);
    }
573567
public function getNotifications($limit = null, $order = 'desc')
    {
        $query = $this->getNotificationRelation()->orderBy('created_at', $order);
        if (! is_null($limit)) {
            $query->limit($limit);
        }

        return $query->get();
    }
724901
public static function findSome (int $limit=0, string $order="DESC")
	{
		$order = static::validateOrder($order);
		return static::limitFindBySql("SELECT * FROM ".static::$tableName." ORDER BY id {$order}", $limit);
	}
370821
public static function classLogHistory($limit = 100, $order = 'desc')
    {
        try {
            return Logs::where('owner_type', get_called_class())->orderBy('updated_at', $order)->limit($limit)->get();
        } catch (Exception $ex) {
            
        }
    }
163898
public function getUpdateSQL($table, $data, $where, $values, $order, $limit) {
        $len = count($table);
        if ($len == 1) {
            $sql = ['UPDATE', implode(' AS ', $table[0]), 'SET'];
        } else {
            $tables = [];
            foreach ($table as $t) {
                $tables[] = implode(' AS ', $t);
            }
            $sql = ['UPDATE', implode(' , ', $tables), 'SET'];
        }

        $fields = [];
        foreach ($data as $field => $value) {
            $field = Condition::cleanField($field);
            if ($value instanceof Query) {
                $value->setBindValues($values);
                $value->setDialect($this);
                $fields [] = $this->sanitize($field) . ' =  (' . $value->__toString() . ')';
            } else if ($value instanceof ImmutableValue) {
                $value->setDialect($this);
                $fields [] = $this->sanitize($field) . ' =  ' . $this->sanitize($value->__toString());
            } else {
                $fields [] = $this->sanitize($field) . ' = ' . $values->addValue($field, $value);
            }
        }

        $sql [] = implode(' , ', $fields);
        if ($where && count($where) > 0) {
            $sql [] = 'WHERE';
            $sql [] = $where->getWhereCondition($this, $values);
        }

        if ($len == 1) {
            if ($order) {
                $_orders = [];
                foreach ($order as $o) {
                    $_orders [] = Condition::cleanField($o [0]) . ' ' . ($o [1] == 'a' ? 'ASC' : 'DESC');
                }
                $sql [] = 'ORDER BY ' . implode(' , ', $_orders);
            }
            if ($limit) {
                $limit2 = $values->addValue('limit', $limit [1]);
                $sql [] = 'LIMIT ' . $limit2;
            }
        }

        return implode(' ', $sql);
    }
956028
public static function findAll($param = null, $order = "", $limit = "",$asArray=false)
    {
        $data = X::app()->db->table(self::tableName())->findAll($param, $order, $limit);
        if (!$asArray && !empty($data)) {
            foreach ($data as $k => $v) {
                $data[$k] = new static($v,false);
            }
        }
        return $data;
    }
307
public function selectAll($where=false, $order=false, $limit=false) {
        $clause = false;
        $values = array();
        if ( is_array($where) ) {
            $retval = self::extractWhere($where, $clause, $values);
            if ( is_string($retval) ) throw new \Exception($val);
        }
        $orderby = '';
        if ( is_string($order) ) {
            $orderby = self::extractOrder($order);
            if ( $orderby === false ) throw new \Exception('Invalid Order value');
        }

        $sql = "SELECT KVS.id AS id, json_body, KVS.created_at, KVS.updated_at
            FROM $this->KVS_TABLE AS KVS
            WHERE $this->KVS_FK_NAME = :foreign_key";
        if ( $clause ) $sql .= ' AND '.$clause;
        if ( $orderby ) $sql .= ' '.$orderby;
        $values[':foreign_key'] = $this->KVS_FK;
        $rows = $this->PDOX->allRowsDie($sql, $values);
        return $rows;
    }
756296
public function getOrders($limit = 10)
    {
        if ($Member = Security::getCurrentUser()) {
            $Orders = $Member->Orders()->sort('TransactionDate', 'DESC');

            $list = new PaginatedList($Orders, Controller::curr()->getRequest());
            $list->setPageLength($limit);

            return $list;
        }

        return false;
    }
685996
public function select(
        $table,
        $conditions = null,
        $fields = null,
        $order = null,
        $limit = null,
        $offset = null
    )
    {
        if (is_null($fields)) {
            $fields = "*";
        }

        $queryString = "SELECT {$fields} FROM {$table} ";

        if (!is_null($conditions)) {
            $queryString .= "WHERE {$conditions} ";
        }

        if (!is_null($order)) {
            $queryString .= "ORDER BY {$order} ";
        }

        if (!is_null($limit)) {
            $queryString .= "LIMIT {$limit} ";
        }

        if (!is_null($offset) && !is_null($limit)) {
            $queryString .= "OFFSET {$offset} ";
        }


        $queryString .= ";";

        $this->query($queryString);

        return $this->countRows();
    }
800261
public function update($table, $feilds, array $where, $limit=0)
	{
		$set = array();
        $vals = array();

		foreach ($feilds as $key => $val) {
			$set[] = "`{$key}` = ?";
            $vals[] = $val;
		}

		$set = implode(', ', $set);

		$sql = "UPDATE {$table} SET {$set} WHERE " . $this->buildWhere($where, $vals);

        if ($limit > 0) {
            $sql .= " LIMIT ".(int)$limit;
        }

        $stmt = $this->prepare($sql);
        return $stmt ? $stmt->execute($vals) : false;
	}