diff options
-rw-r--r-- | app/class/database.class.php | 27 | ||||
-rw-r--r-- | app/class/mysql.class.php | 6 |
2 files changed, 25 insertions, 8 deletions
diff --git a/app/class/database.class.php b/app/class/database.class.php index 4f26c45..c0f13d7 100644 --- a/app/class/database.class.php +++ b/app/class/database.class.php @@ -33,7 +33,7 @@ abstract class database */ public function __destruct() { - $this->close(); + $this->_close(); } /* @@ -41,7 +41,7 @@ abstract class database * first call to this function. This function will need maintained * as new DBMSs are supported. */ - public static function getInstance() : database + private static function getInstance() : database { // TODO } @@ -50,9 +50,26 @@ abstract class database * These functions are to be implemented by DBMS extensions, * providing a uniform interface to database engines. */ - public abstract function close() : void; - public abstract function query(string $query) : array; - public abstract function esc(string $str) : string; + protected abstract function _close() : void; + protected abstract function _query(string $query) : array; + protected abstract function _esc(string $str) : string; + + /* + * Perform a database query and return the results as an array + * of arrays. + */ + public static function query(string $query) : array + { + return self::getInstance()->_query($query); + } + + /* + * Escape a given string for use in a database query + */ + public static function esc(string $str) : string + { + return self::getInstance()->_esc($str); + } } ?> diff --git a/app/class/mysql.class.php b/app/class/mysql.class.php index db0eb7d..57a9819 100644 --- a/app/class/mysql.class.php +++ b/app/class/mysql.class.php @@ -36,7 +36,7 @@ class mysql extends database /* * Close connection to DB */ - public function close() : void + protected function _close() : void { $this->db->close(); } @@ -44,7 +44,7 @@ class mysql extends database /* * Make a query of the database. Return data as an array of arrays. */ - public function query(string $query) : array + protected function _query(string $query) : array { $arr = array(); $res = $this->db->query($query); @@ -59,7 +59,7 @@ class mysql extends database /* * Escape a string for use in a query */ - public function esc(string $str) : string + protected function _esc(string $str) : string { return $this->db->real_escape_string($str); } |