diff --git a/db-mysql.php b/db-mysql.php index 214b34b..a934d27 100755 --- a/db-mysql.php +++ b/db-mysql.php @@ -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(); + } } \ No newline at end of file diff --git a/readme.md b/readme.md index 46a63d1..6c0a83c 100755 --- a/readme.md +++ b/readme.md @@ -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.