Added ability to get data in an order

This commit is contained in:
kolaente 2016-11-12 12:28:18 +01:00
parent 55922ed5cc
commit 2351c688a7
2 changed files with 15 additions and 4 deletions

View File

@ -47,7 +47,7 @@ class db
}
//Daten holen
public function get($where = [], $link = 'AND')
public function get($where = [], $link = 'AND', $orderby = 'id', $order = 'ASC')
{
if (isset($this->col))
{
@ -82,7 +82,10 @@ class db
//print_r($whereAr);
$stmt = $this->dbh->prepare('SELECT * FROM ' . $this->prefix . $this->col . $whereCl);
//Order
$orderstmt = 'ORDER BY '.$orderby.' '.$order;
$stmt = $this->dbh->prepare('SELECT * FROM `' . $this->prefix . $this->col .'`' . $whereCl.$orderstmt);
$stmt->execute($whereAr);
$all = [];
@ -143,7 +146,6 @@ class db
$i++;
}
$stmt .= ') VALUES (' . $valCnt . ')';
//echo $stmt;
$insert = $this->dbh->prepare($stmt);
return $insert->execute($vals);
@ -297,4 +299,10 @@ class db
$this->data = '';
}
//Query
public function query($query)
{
$STH = $this->dbh->prepare($query);
return $STH->execute();
}
}

View File

@ -37,7 +37,7 @@ All data is available via `$db->data`.
### Syntax
`$db->get($where = [], $link = 'AND')`
`$db->get($where = [], $link = 'AND', $orderby = 'id', $order = 'ASC')`
`$where`
An array to return specific data. If provided, only data which matches is returnend. Scheme: `['key' => 'value']`.
@ -49,6 +49,9 @@ All data is available via `$db->data`.
To see it in action, take a look at `example.php` or the "Examples"-Section at the bottom of this document.
`$orderby`
Will sort the Output with this column ascending or descending as specified in `$order`.
## insert()
Inserts data provided via `$db->data` or directly via the function.