# HG changeset patch # User Markus Bröker # Date 1447430502 -3600 # Node ID 4690a1ccb7cce02ab2928629c9a9e8493ba20d9a # Parent 66b604c61e6246514d24dfdb70536c37eb8785fe Anpassungen nach den DB-Tests diff --git a/classes/bfw/database/Database.php b/classes/bfw/database/Database.php --- a/classes/bfw/database/Database.php +++ b/classes/bfw/database/Database.php @@ -101,18 +101,7 @@ * @param $cond * @return array|null */ - public function fetchAll($table, $cond) { - $this->logger->info(sprintf('%s(%s, %s) ', __METHOD__, $table, $cond)); - - return $this->fetch($table, $cond); - } - - /** - * @param $table - * @param $cond - * @return array|null - */ - public function fetch($table, $cond) { + public function fetchAll($table, $cond = 'id > 0') { $this->logger->info(sprintf('%s(%s, %s) ', __METHOD__, $table, $cond)); $stmt = $this->pdo->prepare(sprintf(' @@ -126,7 +115,33 @@ )); if ($stmt->execute()) { - return $stmt->fetch(); + return $stmt->fetchAll(PDO::FETCH_ASSOC); + } + + return null; + } + + /** + * @param $table + * @param $cond + * @return array|null + */ + public function fetch($table, $cond = 'id > 0') { + $this->logger->info(sprintf('%s(%s, %s) ', __METHOD__, $table, $cond)); + + $stmt = $this->pdo->prepare(sprintf(' + SELECT + * + FROM + `%s` + WHERE + %s + LIMIT 1 + ', $table, $cond + )); + + if ($stmt->execute()) { + return $stmt->fetch(PDO::FETCH_ASSOC); } return null; @@ -181,6 +196,7 @@ `%s` WHERE `id` = :id + LIMIT 1 ', $table )); @@ -196,7 +212,7 @@ /** * @param $table - * @param $sys + * @param bool $sys * @return array|null */ public function findAll($table, $sys) { @@ -240,6 +256,7 @@ `%s` WHERE `%s` = :value + LIMIT 1 ', $table, $field ));