From 33499cb813d6aac2abc649dd8e42a3c97ce306b2 Mon Sep 17 00:00:00 2001 From: Malf Furious Date: Sat, 14 Jan 2017 02:13:07 -0500 Subject: Partial commit of initObj function -- this class needs reworked again... --- app/class/database.class.php | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'app/class/database.class.php') 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]; + } + } } ?> -- cgit v1.2.3