--- 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
));