diff options
author | Malf Furious <m@lfurio.us> | 2017-01-14 21:11:31 -0500 |
---|---|---|
committer | Malf Furious <m@lfurio.us> | 2017-01-14 21:11:31 -0500 |
commit | a92f8af0f9aed383e4243e5b2b50d248e843cab4 (patch) | |
tree | 54a0627dec0ea58671b658e1d7243399108aa6d1 /app | |
parent | b2dbfc38866cbe43a0d13324e296740ae347c6fb (diff) | |
download | scrott-a92f8af0f9aed383e4243e5b2b50d248e843cab4.tar.gz scrott-a92f8af0f9aed383e4243e5b2b50d248e843cab4.zip |
Add database class
Diffstat (limited to '')
-rw-r--r-- | app/class/database.class.php | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/app/class/database.class.php b/app/class/database.class.php new file mode 100644 index 0000000..4f26c45 --- /dev/null +++ b/app/class/database.class.php @@ -0,0 +1,58 @@ +<?php + +/* + * SCROTT IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR + * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * For more information, please refer to UNLICENSE + */ + +/* Include database configuration file if it exists */ +define("DATABASE_CONFIG_FILE", "dbconfig.php"); +is_file(DATABASE_CONFIG_FILE) && require_once DATABASE_CONFIG_FILE; + +/* + * This class provides a common interface to various database drivers. + * Scrott provides facilities for interacting with any DBMS that we can + * use in PHP. To provide support for a new DBMS, extend this class and + * implement the abstract functions. Additionally, update the getInstance() + * function in this class so that the new implementation is used under + * appropriate configuration. + */ +abstract class database +{ + private static $instance = NULL; + + /* + * Call this object's close function while being destructed + */ + public function __destruct() + { + $this->close(); + } + + /* + * Return the database instance object, creating it if this is the + * first call to this function. This function will need maintained + * as new DBMSs are supported. + */ + public static function getInstance() : database + { + // TODO + } + + /* + * 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; +} + +?> |