summaryrefslogtreecommitdiffstats
path: root/app/class/database.class.php
diff options
context:
space:
mode:
authorMalf Furious <m@lfurio.us>2017-02-06 00:47:55 -0500
committerMalf Furious <m@lfurio.us>2017-02-06 00:47:55 -0500
commit56a6dda13bb85b25f590fc8a64535bb53c3c2fd2 (patch)
tree8bbca1db84158e1234768ebd1edc325ec70f67d7 /app/class/database.class.php
parente0140672f1fb7c79e47aadad6fbee57e7262b1a2 (diff)
downloadscrott-56a6dda13bb85b25f590fc8a64535bb53c3c2fd2.tar.gz
scrott-56a6dda13bb85b25f590fc8a64535bb53c3c2fd2.zip
Update database API
The abstract functions of database have been made protected and their names prefixed with '_'. The database class has been given new static functions query() and esc(), which call the _query() and _esc() function from the database instance object. This change was made to address the use of db routines from static contexes. Calls like `database::get()->query()` which mix static and instance function access operators, can now be `database::query()`, and all singleton is abstracted away; the instance's destructor continues to close the db connection.
Diffstat (limited to '')
-rw-r--r--app/class/database.class.php27
1 files changed, 22 insertions, 5 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);
+ }
}
?>