Anpassungen nach den DB-Tests
authorMarkus Bröker <broeker.markus@googlemail.com>
Fri, 13 Nov 2015 17:01:42 +0100
changeset 13 4690a1ccb7cc
parent 12 66b604c61e62
child 14 07805bde6517
Anpassungen nach den DB-Tests
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
             ));