diff options
author | Malf Furious <m@lfurio.us> | 2017-01-14 02:13:07 -0500 |
---|---|---|
committer | Malf Furious <m@lfurio.us> | 2017-01-14 02:13:07 -0500 |
commit | 33499cb813d6aac2abc649dd8e42a3c97ce306b2 (patch) | |
tree | 433f019525a42430ada076c608dfa71c0cfbaab0 | |
parent | b6f82bb6552517d8bc442a2087c6c37a33bd18bd (diff) | |
download | scrott-33499cb813d6aac2abc649dd8e42a3c97ce306b2.tar.gz scrott-33499cb813d6aac2abc649dd8e42a3c97ce306b2.zip |
Partial commit of initObj function -- this class needs reworked again...
-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]; + } + } } ?> |