diff options
Diffstat (limited to 'app/class/database.class.php')
-rw-r--r-- | app/class/database.class.php | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/app/class/database.class.php b/app/class/database.class.php index 6c6ecd6..c7ef65b 100644 --- a/app/class/database.class.php +++ b/app/class/database.class.php @@ -42,6 +42,32 @@ abstract class Database public abstract function close(); public abstract function query(string $query) : array; public abstract function esc(string $str) : string; + + /* + * This function will lookup the row from the database on the given + * table containing the given GUID and initialize the class properties + * on this object based on the given field list. + */ + public function initObj(string $table, array $fields, string $guid = NULL) + { + if (is_null($guid)) + return; + + $guid = $this->esc($guid); + $query = "SELECT * FROM " . $table . " WHERE guid = '" . $guid . "'"; + $res = $this->query($query); + + if (!count($res)) + return; + + $res = $res[0]; + + foreach ($fields as $field) + { + if (isset($res[$field])) + $this->$field = $res[$field]; + } + } } ?> |