From f9540b9aab74c8ade96297d621a443e746bce1c4 Mon Sep 17 00:00:00 2001 From: Niko Date: Thu, 10 Feb 2022 02:07:53 +0100 Subject: [PATCH] Fixed DB class not finding $manager + Refactor methods to be similar to Node --- web/src/database.php | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/web/src/database.php b/web/src/database.php index a955646..319ab9c 100644 --- a/web/src/database.php +++ b/web/src/database.php @@ -13,9 +13,18 @@ class DB { $this->db_name = $db_name; } - function query($table, $q) { + function findOne($table, $q) { + $result = $this->find($table, $q); + if ($result === null) + return null; + if (count($result) === 0) + return null; + return $result[0]; + } + + function find($table, $q) { $query = new MongoDB\Driver\Query($q); - $cursor = $manager->executeQuery($this->db_name.'.'.$table, $query); + $cursor = $this->manager->executeQuery($this->db_name.'.'.$table, $query); return $cursor->toArray(); } }